简体   繁体   中英

How to get the Login time and log out (shut down) time of user's computer using Active directory

I am new to .net. I have a requirement that whenever employee switch on(log on) his computer I want to capture that time and whenever user shut down his system again I want to capture that particular time through Active Directory ie I want to capture both login and logout time of particular PC using Active directory using C#. Is it possible? Here I should read this information (login and logout time of PC) from Active Directory only.

Please assist me.

There are the attributes lastLogon and lastLogoff for users and computers, but they are not replicated between domain controllers, so you would need to query all DCs. Also lastLogoff does not seem to be populated...

Your could do any of the following:

  1. Create a service for Client PCs to monitor these events and write them to a data base.
  2. Create a GPO with startup and shutdown scripts to log these events.
  3. Monitor DNS / DHCP for requestas and releases

Information to Startup and Shutdown scripts can be found here and here .

You might have a CMD startup script that does something like this:

echo %Computername% starting at %Date% - %Time% >> \\\\Server\\NULLSHARE\\%Computername%.log

and in a shutdown script:

echo %Computername% shutting down at %Date% - %Time% >> \\\\Server\\NULLSHARE\\%Computername%.log

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM