简体   繁体   English

如何确定当前Windows会话是否被锁定?

[英]How to determine if the current Windows session is locked or not?

I have an application which runs every hour on a Windows XP Machine. 我有一个应用程序,它在Windows XP机器上每小时运行一次。 To run properly, this application requires the current session to be unlocked. 要正常运行,此应用程序需要解锁当前会话。 So I was wondering if there a way to know if the current Windows session is locked or not with C# and .NET 3.5. 所以我想知道是否有办法知道当前的Windows会话是否被C#和.NET 3.5锁定。

UPDATE: The application cannot listen to the SessionNotification events. 更新:应用程序无法侦听SessionNotification事件。 The application can be kicked off anytime and terminates when completed. 该应用程序可以随时启动,并在完成后终止。

Thanks! 谢谢!

These are untested by me, but look interesting. 这些都没有经过我的测试,但看起来很有趣。 I'd give them a test, but my Visual Studio appears to be less than happy with me at the moment. 我给他们一个测试,但我的Visual Studio似乎对我不太满意。

I once used the GetForegroundWindow() function to determine whether a screen saver was running. 我曾经使用GetForegroundWindow()函数来确定屏幕保护程序是否正在运行。 If the return value was NULL , then the screen saver (or, presumably, a locked workstation) was active. 如果返回值为NULL ,则屏幕保护程序(或者,可能是锁定的工作站)处于活动状态。 Note that this was in the early days of Windows NT, is not documented to do this, and there's no guarantee that it will still do the same thing today. 请注意,这是在Windows NT的早期,没有记录这样做,并且不能保证它今天仍然会做同样的事情。

Looking at the Win32 API reference, you may be able to use something like OpenInputDesktop() to get the HDESK of the currently active desktop. 查看Win32 API参考,您可以使用类似OpenInputDesktop()来获取当前活动桌面的HDESK If you can't get a handle to the desktop or if it's different from your thread desktop, then your app is running in a desktop that is not active (and the workstation is probably either in a screensaver state or is locked). 如果您无法获得桌面的句柄或者它与您的线程桌面不同,那么您的应用程序正在未激活的桌面中运行(并且工作站可能处于屏幕保护状态或已锁定)。 No guarantees that this method will work, but it might be worth investigating. 不保证这种方法可行,但可能值得研究。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM