最小化\断开连接时的终端会话在捕获桌面快照时返回空白屏幕

发布于 2024-10-29 12:09:59 字数 1405 浏览 6 评论 0原文

我正在使用下面的 JAVA 代码来捕获远程计算机的桌面,

    Robot robot = new Robot();
    BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));

    ByteArrayOutputStream imageBytes = new ByteArrayOutputStream();
    ImageIO.write(screenShot, "PNG", imageBytes);

    return imageBytes.toByteArray();

但是,当与远程计算机的终端会话最小化或断开连接时,捕获的图像是空白的。我感谢您帮助解决这个问题,至少是最小化的情况。

配置: 我在运行 Windows 7 的物理机和运行 Windows Server 2008 R2 的虚拟机上遇到同样的问题。

来自 MSDN 的更多见解:

为什么在与 RDP 断开连接时会出现黑屏?   http://msdn.microsoft.com/en-us /library/aa383015%28VS.85%29.aspx

这是我的尝试,但以下方法都没有达到目的:  

RDP窗口最小化时如何获取数据?   您可以强制 RDP 显示驱动程序在最小化时发送数据,请尝试以下步骤并让我知道情况如何:   1)添加以下键 HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client\ 创建一个新的 DWORD 值并将其命名为 RemoteDesktop_SuppressWhenMinimized。指定 2 作为值数据。

注意:还尝试将注册表项添加到 HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Terminal Server Client\   2) 禁用位图缓存 (http://technet.microsoft. com/en-us/library/cc737325(WS.10).aspx) 在“远程桌面连接”窗口中,单击“选项”。

在“体验”选项卡上,验证是否选中了“位图缓存”复选框。或者,要禁用位图缓存,请清除位图缓存复选框

I am using the below JAVA code to capture the desktop of a remote machine

    Robot robot = new Robot();
    BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));

    ByteArrayOutputStream imageBytes = new ByteArrayOutputStream();
    ImageIO.write(screenShot, "PNG", imageBytes);

    return imageBytes.toByteArray();

However the captured image is blank, when the terminal session to the remote machine is either minimized or disconnected. I appreciate your help in resolving the issue, at the very least the minimized scenario.

Configuration:
I have the same issues with a physical machine running windows 7 and a virtual machine running windows server 2008 R2.

More insights from MSDN:

Why you get black screen when you disconnect from RDP ?

http://msdn.microsoft.com/en-us/library/aa383015%28VS.85%29.aspx

Here is my attempt to make things work, but none of the following did the trick:  

How to get data when RDP window minimized ?

You can force the RDP display driver to send data when minized, try these steps and let me know how it goes:

1) Add the following key
HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client\ Created a new DWORD value and named it RemoteDesktop_SuppressWhenMinimized. Specified 2 as the value data.

Note: Also tried adding the registry key to HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Terminal Server Client\

2) Disable bitmap caching (http://technet.microsoft.com/en-us/library/cc737325(WS.10).aspx)
In the Remote Desktop Connection window, click Options.

On the Experience tab, verify that the Bitmap caching check box is selected. Or, to disable bitmap caching, clear theBitmap caching check box

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

墨离汐 2024-11-05 12:09:59

如果最小化远程桌面窗口,Windows 会将远程会话切换到无 GUI 模式,并且不显示窗口和控件。因此,TestComplete(或 TestExecute)将无法与测试应用程序的 GUI 交互,因为它不存在,并且您的自动化 GUI 测试将失败。
要解决此问题,您可以在本地计算机(启动远程桌面的位置)上更改远程桌面的注册表设置:
在本地计算机上,关闭所有打开的远程桌面会话。
启动注册表编辑器 (regedit.exe)。
导航到以下注册表项之一,具体取决于您是否希望仅为当前用户或计算机上的所有用户修改远程桌面设置:

HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client
HKEY_LOCAL_MACHINE\Software\Microsoft\终端服务器客户端
创建一个名为 RemoteDesktop_SuppressWhenMinimized 的 DWORD 值并将其设置为 2。

或者您可以通过以下步骤以编程方式执行此操作:

  • 使窗口透明
  • 恢复窗口
  • 捕获
  • 再次最小化它
  • 删除透明度

If you minimize the Remote Desktop window, Windows switches the remote session to the GUI-less mode and does not display windows and controls. As a result, TestComplete (or TestExecute) will be unable to interact with the tested application’s GUI, as it does not exist and your automated GUI test will fail.
To work around the issue, you can change the Remote Desktop’s registry settings on your local computer (where you launch the Remote Desktop):
On your local computer, close all open Remote Desktop sessions.
Launch the Registry editor (regedit.exe).
Navigate to one of the following Registry keys, depending on whether you wish to modify the Remote Desktop settings only for the current user or for all users on the computer:

HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client
HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client
Create a DWORD value named RemoteDesktop_SuppressWhenMinimized and set it to 2.

Or you can do it programmatically by following steps:

  • Transparent the window
  • Restore the Window
  • Capture
  • Minimize it again
  • Remove transparency
日裸衫吸 2024-11-05 12:09:59

去年我们的项目中遇到了类似的问题...我们可以找到任何稳定且永久的解决方案...但是,这是我们的解决方法...

我们必须在 5 个远程桌面上运行(这将占用屏幕)失败期间也会捕获)..但是,正如您已经想到的,如果我们断开会话或最小化 RDC 窗口,则会捕获空白屏幕截图。因此,我们又添加了一台虚拟机来连接其他五个测试盒。该虚拟机的任务是保持会话活动并调整大小到其他 5 个盒子......这对我们有用。

We had similar problem in our project last year...we could find any stable and permanent solution....however here is how a work around worked for us...

We had to run on 5 remote desktops (which will take screens capture as well during failure) ..however as you have figured already if we disconnect session or minimise the RDC Window blank screenshot is captured. Therefore we had added one more VM to connect those other five test boxes. The task for that VM is to keep session active and resized to other 5 boxes...this worked for us.

御守 2024-11-05 12:09:59

如果将远程桌面连接到测试计算机,请确保完成后重新启动计算机,否则桌面将保持锁定状态并且屏幕截图将不起作用。

我不相信还有其他方法可以解决这个问题。

If you connect a remote desktop to the test machine, make sure to reboot the machine when you are done, otherwise the desktop will remain locked and screen captures will not work.

I don't believe there is any other way around the issue.

草莓味的萝莉 2024-11-05 12:09:59

我刚刚将客户端配置为自动登录、禁用屏幕保护程序并在每个客户端上安装了 VNC 服务器。

基本上,请确保屏幕始终打开,并且不要通过 RDP 访问它们。

这适用于物理 PC 和 Hyper-V 服务器上托管的虚拟机。

我什至编写了一个小型 .NET 桌面客户端,在一个窗口中运行多个 VNC 客户端,这样我们就可以看到所有客户端上发生的情况。我们有一台运行此程序的旧电脑,其显示器位于橱柜顶部,以便 (a) 让开发人员查看是否有客户端挂起、是否打开了数百个浏览器窗口等,以及 (b) 让非开发人员看起来印象深刻走过去。

I just configured the clients to auto logon, disabled the screen saver and installed a VNC server on each client.

Basically, make sure the screen is always on, and don't RDP into them.

This worked on both physical PCs and on virtual machines hosted on a Hyper-V server.

I even wrote a small .NET desktop client that ran multiple VNC clients inside a single window, so we could see what was happening on all the clients. We had an old PC running this with it's monitor on top of a cupboard to (a) let the developers see if any client had hung, had hundreds of browser windows open, etc. and (b) to look impressive for any non-developers walking past.

っ左 2024-11-05 12:09:59

上述答案的更简单替代方案是将终端会话 (RDP) 转换为控制台会话。然后,会话将显示到物理屏幕(切换当前登录物理机的任何人的用户)。以下命令执行此操作:

for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (tscon.exe %%s /dest:console)

A simpler alternative to the above answers to to transmute the terminal session (RDP) into the console session. The session will then display to the physical screen (Switching the user of anyone currently logged into the physical machine). The following command does this:

for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (tscon.exe %%s /dest:console)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文