How to note the time (possibly datetime) of PC Lock, Shutdown, Restart Event?
I am trying to create a service which tracks the desktop events like LOCK, LOGOFF, SHUTDOWN etc,
I need开发者_运维问答 to write the time (and date) in a text file,
regards.
you should be able to get the information you are looking for from Microsoft.Win32.SystemEvents.
The SessionSwitch event will tell you when the user is switched or the computer is locked. http://msdn.microsoft.com/en-us/library/microsoft.win32.sessionswitcheventargs(v=VS.90).aspx
You can handle the events on the SystemEvents class.
Implement the service's OnStart, OnShutdown and OnSessionChange methods. Not so sure that OnSessionChange still works on Vista and Win7, services run in an isolated session called Session 0. I seriously doubt it, no workaround for it.
SENS ISensLogon has Logon/Logoff callbacks
How can I programmatically determine if my workstation is locked has a lot of information on this.
精彩评论