如何从一个WPF应用程序检测锁定该计算机的命令? [英] How do I detect a Lock This Computer command from a WPF application?

查看:159
本文介绍了如何从一个WPF应用程序检测锁定该计算机的命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

宁愿在C#中的答案,NET 3.5的使用WPF(Windows窗体也没关系)

Would prefer an answer in C#, .Net 3.5 using WPF (Windows Forms also okay)

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

I have an application that is essentially a toolbar window or tray icon. It needs to detect if a user locks his/her workstation and walks away in order to update the person's status in a centralized system.

我可以检测会话开关或注销很轻松地使用SystemEvents,但我不能为我的生活弄清楚如何检测或接收锁定的事件。

I can detect a session switch or a logout easily enough, using the SystemEvents, but I cannot for the life of me figure out how to detect or receive an event on Lock.

感谢您的任何帮助。

推荐答案

在处理的 Microsoft.Win32.SystemEvents.SessionSwitch 事件(这听起来像你已经做检测注销),请检查是否原因是的 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;
         // ...
     }
 }

这篇关于如何从一个WPF应用程序检测锁定该计算机的命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆