Windows锁定屏幕“后面"会发生什么? [英] What happens 'behind' the windows lock screen?

查看:130
本文介绍了Windows锁定屏幕“后面"会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在从事Windows自动化和监视.

I have been working on windows automation and monitoring.

锁定Windows计算机的屏幕时会发生什么?

What exactly happens when I lock the screen of a windows machine?

目前,我正在使用Windows 7,如果切换到Vista或服务器版本,行为会有很大的不同吗? 仍然存在可以通过api访问的桌面吗? 我知道我仍然可以将击键和鼠标单击发送到特定窗口(通过 ControlSend ControlClick ),但似乎没有桌面"本身.

I am working with Windows 7 at the moment, are there big differences to the behavior if I switch to Vista or the server versions? Is there still a desktop that can be accessed via api's? I know that i can still send key strokes and mouse clicks to specific windows (via ControlSend and ControlClick), but there seems to be no "desktop" itself.

有人可以对这件事进行一些说明吗?还是将我指向一个可读的资源,以便我可以对该主题进行概述?

Could someone shed some light on this whole thing or point me at a readable source where I could get an overview over the topic?

推荐答案

基本上,发生的事情是Windows切换到安全桌面,使其成为当前桌面,因此现在将输入与之关联.

Basically what happens is that Windows switches to the secure desktop, makes it the current one, so input is now associated with it.

旧台式机仍然保留原样:台式机上的所有HWND仍在那儿,并且连接到该台式机的任何线程仍可以访问这些HWND,获取其位置等等.只要发送消息的线程也在该桌面上,您仍然可以将消息发送到此桌面上的Windows.

The old desktop remains where it was: all the HWNDs on the desktop are still there, and any thread attached to that desktop can still access those HWNDs, get their location, and so on. You can still send messages to windows on this desktop, so long as the thread sending the message is also on that desktop.

但是,由于桌面现在处于非活动状态,因此它无法接收输入. GetForegroundWindow将返回NULL(IIRC),并且您不能再使用SendInput,因为输入现在属于另一个桌面上的一个线程;该非活动桌面上的任何控件都无法获得焦点.

However, since the desktop is now inactive, it cannot receive input. GetForegroundWindow will return NULL (IIRC), and you can't use SendInput any longer, since input now belongs to [a thread on] a different desktop; no controls on that inactive desktop can receive focus.

请注意,将按键消息发送到没有焦点的控件有时会导致意外行为,因为应用程序或控件通常从不希望在没有先获得焦点的情况下接收键盘输入. (例如,对于在WM_SETFOCUS中设置某种输入上下文并在WM_KILLFOCUS中将其清除的控件来说,这可能是有问题的.)

Note that sending keypress messages to a control that doesn't have focus can sometimes cause unexpected behavior, since the app or control generally never expects to receive keyboard input without getting the focus first. (This can be problematic for controls that set up some sort of input context in WM_SETFOCUS and clear it up in WM_KILLFOCUS, for example.)

简而言之,UI仍然存在:您可以对它进行某些查询,但是您不再像在常规桌面上那样通过发送输入来使其自动化,并且某些其他与焦点或输入有关的功能可能会失败

In short, the UI is still there: you can do certain queries against it, but you can no longer automate it as you could on a regular desktop by sending input, and some other functions that relate to focus or input may fail.

我对AutoHotKey不太熟悉,但是功能的名称和描述表明它在很大程度上依赖于基础Win32 SendInput API.当台式机处于非活动状态时,这对于键盘输入根本不起作用.

I'm not super familiar with AutoHotKey, but the name and description of functionality suggests that it's heavily reliant on the underlying Win32 SendInput API. This won't work at all for keyboard input when a desktop is inactive.

要合理地了解台式机的工作原理以及它们与Winstations,锁定的台式机的关系等,请查看

For a reasonable overview of how desktops work and how they relate to winstations, the locked desktop, and so on, check out the Desktop article on MSDN.

我过去在台式机和自动化系统中遇到的一个问题是:如何离开长时间运行的测试,该测试使用某种形式的用户输入自动化(鼠标,键盘模拟),但仍锁定我的PC,因此有人不能只路过并干扰它.锁定PC后,桌面将处于非活动状态,因此自动化将停止工作.如果启动了屏幕保护程序,也会发生类似的问题:台式机切换,并且自动化失败.

One issue that I've run into in the past with desktops and automation is: how to I leave a long-running test that's using some form of user input automation (mouse, keyboard simulation), but still lock my PC so that someone can't just walk by and interfere with it. Once you lock the PC, the desktop is inactive, and so the automation stops working. A similar issue happens if the screensaver kicks in: the desktop switches, and the automation fails.

一种解决方案是使用两台PC:我们将它们分别称为Main和Test:在Main上,将远程终端服务客户端打开到Test机器上,然后在测试机器上运行自动化测试,但是要从Terminal Services Client窗口运行在主机上.现在最酷的部分是:您可以最小化该TSC窗口,甚至锁定主计算机(或让屏幕保护程序进入),并且虚拟会话将继续工作,并认为它仍处于活动状态-只是没人在付钱.注意力.这是在活动桌面上创建连接"会话的一种方法,但是没有人可以干涉,因为它受到了主机锁定桌面的保护.

One solution is to use two PCs: let's call them Main and Test: from Main, open a remote terminal services client onto the Test machine, and then run the automated test on the test machine, but from a terminal services client window on the Main machine. Now the cool part: you can minimize that TSC window, or even lock the Main machine (or let the screensaver kick in), and that virtual session will continue working, thinking that it is still active - it's just that nobody is paying it any attention. This is one way to create a "connected" session with an active desktop, but one that no-one can interfere with, because it's protected behind the locked desktop of the Main machine.

这篇关于Windows锁定屏幕“后面"会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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