Terminal session when minimized\disconnected returns a blank screen upon capturing desktop snapshot
Asked Answered
B

5

17

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

Blossom answered 30/3, 2011 at 22:25 Comment(2)
I see you tagged this question as selenium. Are you running selenium tests in the remote session? If so, why not just do the screen capture from within the remote session, as part of your selenium script?Enclave
Hi, did you finally solve this issue in some concrete way? Same problem here . TnxDingdong
Q
9

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
Quatrain answered 4/2, 2016 at 6:7 Comment(1)
Where do you guys find out about these hidden DWORDs??? Maybe this should be a question onto itself? This is an important setting; why hide it?Blabber
C
1

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.

Coats answered 2/1, 2015 at 3:45 Comment(0)
H
0

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.

Horrid answered 28/6, 2011 at 15:54 Comment(0)
D
0

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.

Dialectician answered 20/2, 2015 at 17:21 Comment(0)
M
0

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)
Midinette answered 14/7, 2018 at 8:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.