1

This is in regards to applications that run in the taskbar but should be applicable to standard apps, Winforms, WPF, etc.

Question: I am after some method (preferably via managed code) to be notified when a user either has their screen "locked" while my app is running and/or know when they log back in.

GMail Notifier does this sort of thing for example, if my PC is locked for a while when I log in again it shows a list of emails that arrived since locking the PC. I'm looking to replicate that kind of functionality.

Does anyone have any ideas on how to accomplish this?

John Rudy
  • 37,282
  • 14
  • 64
  • 100
Paul Kohler
  • 2,684
  • 18
  • 31
  • 1
    http://stackoverflow.com/questions/603484/checking-for-workstation-lock-unlock-change-with-c – Mike Daniels May 06 '10 at 21:52
  • @Mike Daniels, that helped too - it pointed me to `Microsoft.Win32.SystemEvents` but I had not realised that it included the `SessionSwitch` event. Will need to test it out a bit more... http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.aspx – Paul Kohler May 06 '10 at 23:32

2 Answers2

0

You want to hook into the System Event Notification Service and subscribe to the ISensLogon DisplayLock/DisplayUnlock events.

Nick Bastin
  • 30,415
  • 7
  • 59
  • 78
  • Do you know of a good managed implementation using `ISensLogon`? – Paul Kohler May 06 '10 at 23:35
  • I don't know of an explicitly managed implementation, but there's an example implementation in Python at http://timgolden.me.uk/python/win32_how_do_i/track-session-events.html – Nick Bastin May 07 '10 at 02:56
0

The question mentioned by Mike Daniels has answers:

Checking for workstation lock/unlock change with c#

The one I prefer is using is SessionSwitchReason:

http://msdn.microsoft.com/en-us/library/microsoft.win32.sessionswitchreason.aspx

Community
  • 1
  • 1
Paul Kohler
  • 2,684
  • 18
  • 31