I've tried looking at SystemEvents but I don't see anything that has to do with capturing an event if the user locks the PC. Does such an event handler exist in C#?
Thanks
Printable View
I've tried looking at SystemEvents but I don't see anything that has to do with capturing an event if the user locks the PC. Does such an event handler exist in C#?
Thanks
Looks like it:
http://bytes.com/forum/thread536508.htmlCode:using System;
using Microsoft.Win32;
public class App
{
static void Main()
{
SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
Console.ReadLine(); // block main thread
// !! detach the eventhandler when the application terminates, or you will
leak a handle.
SystemEvents.SessionSwitch -= SystemEvents_SessionSwitch;
}
static void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
if(e.Reason == SessionSwitchReason.SessionLock)
{...}
}
}
}
Quote:
Originally Posted by dglienna
Awesome! Thank you, I cannot believe the answer was right under my nose. Still having some problems with this as the events do not get generated but I'm taking a look at the website link you gave for more clues. I think I'll find an answer soon. Thank you!
Did you every solve your issue of not capturing the events. I am having the same issue.
It has been a long day so I might be missing something. I will take another look in the morning.
Windows service not able to capture Login/Lock/Unlock in Win7.
if any one knows the solution or any idea or approach, please help me out.
waiting for all of your positive response.
Thanks in Advance..