【问题标题】:How do I detect a Lock This Computer command from a WPF application?如何从 WPF 应用程序中检测到 Lock This Computer 命令?
【发布时间】:2009-03-16 23:35:21
【问题描述】:

希望使用 WPF 在 C#、.Net 3.5 中得到答案(Windows 窗体也可以)

我有一个应用程序,它本质上是一个工具栏窗口或托盘图标。它需要检测用户是否锁定了他/她的工作站并走开,以便在集中式系统中更新此人的状态。

我可以使用 SystemEvents 很容易地检测到会话切换或注销,但我终其一生都无法弄清楚如何检测或接收 Lock 事件。

感谢您的帮助。

【问题讨论】:

标签: c# wpf desktop locking


【解决方案1】:

当您处理Microsoft.Win32.SystemEvents.SessionSwitch 事件时(听起来您已经在检测注销),检查Reason 是否为SessionSwitchReason.SessionLock

 using Microsoft.Win32;
 // ...
 // Somewhere in your startup, add your event handler:
    SystemEvents.SessionSwitch += 
       new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
 // ...

 void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
 {
     switch(e.Reason)
     {
         // ...
         case SessionSwitchReason.SessionLock:
            // Do whatever you need to do for a lock
            // ...
         break;
         case SessionSwitchReason.SessionUnlock:
            // Do whatever you need to do for an unlock
            // ...
         break;
         // ...
     }
 }

【讨论】:

    【解决方案2】:

    【讨论】:

    • 是否有理由这样做而不是处理 SystemEvents.SessionSwitch?
    • 仅当您不知道 SessionSwitch 时。我一直到现在。
    【解决方案3】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-04
      相关资源
      最近更新 更多