以编程方式确定锁定工作站的持续时间? [英] Programmatically Determine a Duration of a Locked Workstation?

查看:73
本文介绍了以编程方式确定锁定工作站的持续时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过代码确定机器被锁定了多长时间?

How can one determine, in code, how long the machine is locked?

也欢迎使用C#之外的其他想法。

Other ideas outside of C# are also welcome.

我喜欢Windows服务的想法(并接受了它)是为了简洁和整洁,但不幸的是,我认为它在这种情况下不适合我案件。我想在工作场所而不是在家(或者我想在家中)上在工作站上运行它,但是出于mod的考虑,这很难解决。实际上,这就是我自己滚动自己的原因的一部分。

I like the windows service idea (and have accepted it) for simplicity and cleanliness, but unfortunately I don't think it will work for me in this particular case. I wanted to run this on my workstation at work rather than home (or in addition to home, I suppose), but it's locked down pretty hard courtesy of the DoD. That's part of the reason I'm rolling my own, actually.

我还是会写下来,看看是否可行。谢谢大家!

I'll write it up anyway and see if it works. Thanks everyone!

推荐答案

我以前没有发现过,但是从任何应用程序中,您都可以连接SessionSwitchEventHandler。显然,您的应用程序将需要运行,但是只要它是运行状态即可:

I hadn't found this before, but from any application you can hookup a SessionSwitchEventHandler. Obviously your application will need to be running, but so long as it is:

Microsoft.Win32.SystemEvents.SessionSwitch += new Microsoft.Win32.SessionSwitchEventHandler(SystemEvents_SessionSwitch);

void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
{
    if (e.Reason == SessionSwitchReason.SessionLock)
    { 
        //I left my desk
    }
    else if (e.Reason == SessionSwitchReason.SessionUnlock)
    { 
        //I returned to my desk
    }
}

这篇关于以编程方式确定锁定工作站的持续时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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