1

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.

Rookie Programmer Aravind
  • 11,952
  • 23
  • 81
  • 114

5 Answers5

2

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

Mikael
  • 443
  • 4
  • 9
1

You can handle the events on the SystemEvents class.

Wim Coenen
  • 66,094
  • 13
  • 157
  • 251
1

How can I programmatically determine if my workstation is locked has a lot of information on this.

Community
  • 1
  • 1
jasper
  • 3,424
  • 1
  • 25
  • 46
1

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
1

SENS ISensLogon has Logon/Logoff callbacks

Ohad Schneider
  • 36,600
  • 15
  • 168
  • 198