0

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

4

3 回答 3

5

您可以编写一个程序来通过SystemEventsin监视用户会话状态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;
  }
}

在您的情况下,您可以Process.Start(...)在检测到SessionLogonor时执行此操作SessionUnlock

于 2013-01-19T22:50:21.543 回答
0

看起来SO已经有一些关于这类事情的信息。c# 中的注册表修改看起来可以解决问题。

以编程方式在登录时启动应用程序

于 2013-01-19T22:37:55.940 回答
0

我想就是你要找的人!这是相关的片段:

WshShell shell = new WshShell();
string shortcutAddress = startupFolder + @"\MyStartupShortcut.lnk";
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
shortcut.Description = "A startup shortcut. If you delete this shortcut from your computer, LaunchOnStartup.exe will not launch on Windows Startup"; // set the description of the shortcut
shortcut.WorkingDirectory = Application.StartupPath; /* working directory */
shortcut.TargetPath = Application.ExecutablePath; /* path of the executable */
shortcut.Save(); // save the shortcut 
于 2013-01-19T22:45:21.957 回答