我如何编程方式确定如果我的工作站被锁定? [英] How can I programmatically determine if my workstation is locked?

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

问题描述

我写了一些生产力/度量工具,为我自己,帮助监控整个一天,我的焦点。最近,我发现我倾向于下车赛道比平常更多,觉得有必要起床去散步/饮料/等等,我很担心,我在浪费了太多的时间。

I'm writing up some productivity/metrics tools for myself to help monitor my focus throughout the day. Recently, I've noticed that I tend to get off track more than usual and feel the need to get up and go for walks/drinks/etc and I'm concerned that I'm "wasting" too much time.

当我去任何地方,我只要打开它,因为我返回(即使我只是在看我的办公桌等),因为我总是锁定我的电脑,我想知道我怎么能确定,在code,该机多久锁定。

Since I always lock my computer when I go anywhere, and I unlock it as soon as I return (even if I'm just reading at my desk, etc), I was wondering how I can determine, in code, how long the machine is locked.

我在C#写这是否有帮助,但我开到其他的想法。

I'm writing this in C# if that helps, but I'm open to other ideas.


我喜欢Windows服务理念(并且已经接受了它),为了简单和干净,但不幸的是,我不认为这会为我在这个特殊的情况下工作。我想我的工作,而不是家庭(或除了家里,我想)的工作站上运行它,但它锁定了美国mod的pretty硬礼遇。这就是我在我自己的滚动,实际上的原因之一。

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天全站免登陆