C ++:在不禁用UAC的情况下截取Windows登录屏幕/UAC提示的屏幕截图 [英] C++: Taking a screenshot of the Windows Logon Screen/UAC Prompts without disabling UAC

查看:196
本文介绍了C ++:在不禁用UAC的情况下截取Windows登录屏幕/UAC提示的屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在互联网上寻找有关此问题的答案,但似乎并没有直接得到答案,所以我想问一下.

I've been looking all over the internet for an answer to this, and it just doesn't seem to be directly answered, so I thought I would ask.

情况:我想对当前计算机屏幕上的屏幕截图进行截图.如果是Windows登录屏幕,我希望是这样.如果它是活动用户的桌面,我想成为那个.如果用户提升他们的应用程序,并且出现UAC提示,我希望是那样.

Case scenario: I want to take a screenshot of what is currently on the computer screen. If it's the Windows Logon screen, I want it to be that. If it's the active user's desktop, I want to to be that. If the user elevates their application, and the UAC prompt shows up, I want it to be that.

根据大量的阅读和反复试验,我当前的设置如下:

As per lots of reading and trial and error, my current setup is as follows:

  • 程序作为Windows服务运行
  • 获取活动用户的令牌
  • 使用用户的令牌运行CreateProcessAsUser来生成自身的另一个实例
  • 获取屏幕截图,然后通过管道将其传输回来.

现在,这对于已登录的用户非常有用,除了启用UAC提示时屏幕截图为黑色之外.

Right now this is working great for a logged on user, except that screenshot is black when a UAC prompt is enabled.

此外,该方法显然无法获得登录屏幕.

Also, this method obviously won't work for getting the logon screen.

从根本上讲,我想知道TeamViewer如何实现这种目标?它能够在登录屏幕和用户会话之间完美切换,同时还可以捕获UAC提示.我对它如何实现这一目标感到非常好奇.

Fundamentally I am wondering how exactly does TeamViewer go about achieving this sort of thing? It is able to switch between the logon screen and a user's session flawlessly, whilst also capturing UAC prompts. I am immensely curious as to how it achieves this.

谢谢大家!

推荐答案

根据Davison的建议,我已经弄清楚了如何做到这一点,它涉及多个步骤.

As per the advice of Davison, I have figured out how to do this, and it involves multiple steps.

首先,必须使用CreateProcessAsUser在控制台会话(从WTSGetActiveConsoleSessionId获得)中创建一个进程.需要注意的一点是,该过程必须具有管理特权,而仅仅获得用户令牌的句柄就不会具有管理特权.显然,解决此问题的方法是获取具有管理特权的进程的句柄,获取该进程的令牌,对其进行复制并将其与CreateProcessAsUser一起使用.我用于此的过程是Winlogon.

Firstly, one must use CreateProcessAsUser to create a process inside the console session (obtained from WTSGetActiveConsoleSessionId). Something to note is that this process must have administrative privileges, which simply getting a handle to the user's token will not do. The way around this evidently, is to get a handle to a process running with administrative privileges, get this processes' token, duplicate it, and use that with CreateProcessAsUser. The process I used for this was Winlogon.

在此之后,剩下的就很简单了.使用OpenInputDesktop获取用户当前正在查看的桌面的句柄(对于实际的桌面,它将为Default;对于UAC提示和登录屏幕,它将为Winlogon).之后,使用SetThreadDesktop将进程的线程设置为适当的桌面,然后捕获屏幕.假设您的进程具有创建Winlogon桌面的句柄的特权,则可以捕获登录屏幕/uac提示和常规用户桌面.

After this, the rest is quite simple; use OpenInputDesktop to get a handle to the desktop the user is currently seeing (it will be Default for actual desktop, and Winlogon for the UAC Prompt and login screen). After this, use SetThreadDesktop to set your processes' thread to the appropriate desktop, and capture the screen. Assuming that your Process has the privileges to create a handle to the Winlogon desktop, you will be able to capture the login screen/uac prompts and the regular user desktop.

再次感谢戴维森,他为我指明了正确的方向.

Again, thanks to Davison, who pointed me in the right direction.

这篇关于C ++:在不禁用UAC的情况下截取Windows登录屏幕/UAC提示的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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