你可以写一个程序,通过监控用户会话状态SystemEvents中Microsoft.Win32:
// Put this somewhere in your console app/windows form initialization code.
SystemEvents.SessionSwitch += OnSessionSwitch;
// Put this method in your console app/windows form somewhere.
static void OnSessionSwitch(object sender, SessionSwitchEventArgs e)
{
switch (e.Reason)
{
case SessionSwitchReason.SessionLogon:
// User has logged on to the computer.
break;
case SessionSwitchReason.SessionLogoff:
// User has logged off from the computer.
break;
case SessionSwitchReason.SessionUnlock:
// The computer has been unlocked.
break;
case SessionSwitchReason.SessionLock:
// The computer has been locked.
break;
}
}
Run Code Online (Sandbox Code Playgroud)
在您的情况下,您可以Process.Start(...)在检测到SessionLogon或时执行SessionUnlock.