The following C# code will register for lock/unlock status notification and do the operation for corresponding status.
void AddLockStatusNotificationHandler()
{
Microsoft.Win32.SystemEvents.SessionSwitch += new Microsoft.Win32.SessionSwitchEventHandler(OnSessionSwitch);
}
void OnSessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
{
if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock)
{
//System Locked
}
else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
{
//System Unlocked
}
}
{
Microsoft.Win32.SystemEvents.SessionSwitch += new Microsoft.Win32.SessionSwitchEventHandler(OnSessionSwitch);
}
void OnSessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
{
if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionLock)
{
//System Locked
}
else if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
{
//System Unlocked
}
}
No comments:
Post a Comment