每次登录后启动程序

Ter*_*rii 0 c# windows login winforms

我试图在互联网上找到这个,没有运气.我想在每次登录后启动程序(LoginUI.exe).是否可以检测用户何时锁定了他/她的计算机(Winkey + L)然后启动我的程序?如果这不可能,那么一旦用户刚刚登录,有没有办法检测?

Eri*_*rik 5

你可以写一个程序,通过监控用户会话状态SystemEventsMicrosoft.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.