可能重复:
How can I programmatically determine if my workstation is locked?
Checking for workstation lock/unlock change with c#确定当用户锁定/解锁其PC
我想确定时,在Windows(XP,或7)机被锁定,并解锁。
我想创建一个时间表活动记录应用程序,预填充时间,午餐,休息等等,将是非常有用的。
当Windows操作系统被锁定和解锁时,是否可以启动一个事件?
可能重复:
How can I programmatically determine if my workstation is locked?
Checking for workstation lock/unlock change with c#确定当用户锁定/解锁其PC
我想确定时,在Windows(XP,或7)机被锁定,并解锁。
我想创建一个时间表活动记录应用程序,预填充时间,午餐,休息等等,将是非常有用的。
当Windows操作系统被锁定和解锁时,是否可以启动一个事件?
你需要获得一个会话变更通知,通过看on PInvoke here
正如注释状态开始,有人应该考虑这种使用这个API的对商业的影响。
一旦用户意识到这种监控,他们可能会试图离开会话解锁,甚至共享密码,这将是反生产力。
这是一个应用程序让我用来帮助提醒我,当我在,离开我的办公桌等,因为当我填写时间表,这不是'公司' – cometbill 2012-02-27 11:03:21
试试这个(found here):
SystemEvents.SessionSwitch +=
new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
// unhook static eventhandler when application terminates!
//Handle event
static void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
Console.WriteLine(e.Reason.ToString());
}
这里是一个工作示例。运行此操作,锁定并解锁工作站,并观察输出:
using System;
using Microsoft.Win32;
namespace ConsoleApplication1
{
class Program
{
private static SessionSwitchEventHandler sseh;
static void Main(string[] args)
{
sseh = new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
SystemEvents.SessionSwitch += sseh;
while(true) {}
}
static void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
Console.WriteLine(e.Reason.ToString());
}
}
}
您可能还想检测屏幕保护程序何时运行。
我以前做过这件事,但这听起来很邪恶。 – Jodrell 2012-01-30 17:22:29
检查这一个:http://www.codeproject.com/Articles/13774/Detecting-Windows-Workstation-Locked-Unlocked-in-N – 2012-01-30 17:23:03
你介意让我知道你在哪里工作,所以我可以将它添加到我的黑名单。 – 2012-01-30 17:23:28