How to determine Lock This Computer command from a WPF application?

Prefer a response to C #,. Net 3.5 using WPF (Windows Forms is also good)

I have an application, which essentially is a toolbar window or tray icon. He must determine if the user is blocking his workstation and leaves to update the status of a person in a centralized system.

I can easily detect a session switch or logout using SystemEvents, but I cannot figure out for life how to detect or receive an event in Lock.

Thanks for any help.

+19
c # locking wpf desktop
Mar 16 '09 at 23:35
source share
3 answers

When you are handling the Microsoft.Win32.SystemEvents.SessionSwitch event (as it seems you are already doing to detect a SessionSwitchReason ), check Reason SessionSwitchReason .SessionLock :

  using Microsoft.Win32; // ... // Somewhere in your startup, add your event handler: SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch); // ... void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e) { switch(e.Reason) { // ... case SessionSwitchReason.SessionLock: // Do whatever you need to do for a lock // ... break; case SessionSwitchReason.SessionUnlock: // Do whatever you need to do for an unlock // ... break; // ... } } 
+42
Mar 16 '09 at 23:44
source share

You need p / invoke WTSRegisterSessionNotification. Sample code here

+2
Mar 16 '09 at 23:42
source share
+1
Mar 16 '09 at 23:43
source share



All Articles