As stated in StackOverflow's answer: fooobar.com/questions/59430 / ... , you should take a look at the SystemEvents.SessionSwitch Event .
Sample code can also be found in the answer.
, fooobar.com/questions/59430/..., , , , RTM Windows 8 .NET framework 4.5.
, .
using System;
using Microsoft.Win32;
namespace WinLockMonitor
{
class Program
{
static void Main(string[] args)
{
Microsoft.Win32.SystemEvents.SessionSwitch += new Microsoft.Win32.SessionSwitchEventHandler(SystemEvents_SessionSwitch);
Console.ReadLine();
}
static void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
{
if (e.Reason == SessionSwitchReason.SessionLock)
{
Console.WriteLine("I left my desk");
}
else if (e.Reason == SessionSwitchReason.SessionUnlock)
{
Console.WriteLine("I returned to my desk");
}
}
}
}