如何判断当前是否显示登录屏幕? [英] How to tell that the logon screen is currently displayed?

查看:141
本文介绍了如何判断当前是否显示登录屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写将使用local system凭据运行的服务应用程序.我将需要从我的服务中了解在任何特定时间是否显示Windows登录屏幕.有什么办法吗?

I am writing a service application that will run with local system credentials. I will need to know from my service if the Windows logon screen is displayed at any particular time. Is there any way to do this?

PS.通过锁定工作站可以显示的屏幕:

PS. The screens that can be brought up by locking the workstation:

或尝试切换用户:

或在Ctrl + Alt + Del之后:

Or after a Ctrl+Alt+Del:

PS.我需要它才能在Windows XP及更高版本上运行.

PS. I need this to run on Windows XP and up.

编辑:到目前为止,我想到的唯一可行的解​​决方案是查看LogonUI.exe进程是否正在运行.这种方法的问题是如何区分实际的系统登录过程和具有该映像名称的任何其他过程?

The only viable solution that I came up with so far is to see if LogonUI.exe process is running. The issue with this approach is how to distinguish between the actual system logon process and any other process that has that image name?

推荐答案

如注释中所述,您试图检测交互式桌面会话中的进程是否应显示消息框.如果交互式会话未处于活动状态,则没有任何意义.

As described in the comments you are trying to detect whether or not a process in an interactive desktop session should show a message box. There being no point doing so if the interactive session is not active.

在这种情况下,我认为您建议的解决方案是错误的.相反,您应该通过调用WTSRegisterSessionNotification注册会话更改通知.当您执行此操作时,您将收到发送的WM_WTSSESSION_CHANGE消息,使您可以跟踪当前状态.

In which case I believe that your proposed solution is the wrong one. Instead you should register for session change notifications by calling WTSRegisterSessionNotification. When you do this you'll get sent WM_WTSSESSION_CHANGE messages that allow you to keep track of the current state.

请注意,您是在桌面应用程序而不是服务中执行此操作.该服务仍将其消息发送到桌面应用程序.但是,桌面应用程序现在知道是否值得向他们展示.

Note that you do this in your desktop app rather than the service. The service still sends its messages to the desktop app. But the desktop app now knows whether or not it is worth showing them.

更新

雷米(Remy)在评论中提出了一种更好的方法:

Remy suggests a better way in the comments:

如果正在使用单独的应用程序,则根本没有理由检测会话更改,该应用程序可以简单地检查其当前分配的工作站/桌面是否为当前交互式工作站/桌面,将GetThreadDesktop()GetThreadDesktop()进行比较.例如c5>.

And if a separate app is being used, there is no reason to detect session changes at all, that app can simply check if its currently assigned workstation/desktop is the currently interactive workstation/desktop instead, comparing GetThreadDesktop() to OpenInputDesktop(), for instance.

这篇关于如何判断当前是否显示登录屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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