Note that there are some explanatory texts on larger screens.

plurals
  1. POScreen capture with C# and Remote Desktop problems
    text
    copied!<p>I have a C sharp console application that captures a screenshot of a MS Word document several times. It works great, but when I place this application on a remote windows XP machine it works fine whilst I am remoted in i.e. my remote desktop is visible but if I run my app and leave remote desktop (minimize it, not even <strong>log off which I want to do</strong>) the screenshots it takes are blank!</p> <p>The Screenshot app is being run by a service that runs as SYSTEM user.</p> <p>How can I keep the GUI alive for windows even when there are no users connected?</p> <p>Here is the code I use:</p> <pre><code>public Image CaptureWindow(IntPtr handle) { // get te hDC of the target window IntPtr hdcSrc = User32.GetWindowDC(handle); // get the size User32.RECT windowRect = new User32.RECT(); User32.GetWindowRect(handle, ref windowRect); int width = windowRect.right - windowRect.left; int height = windowRect.bottom - windowRect.top; // create a device context we can copy to IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc); // create a bitmap we can copy it to, // using GetDeviceCaps to get the width/height IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height); // select the bitmap object IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap); // bitblt over GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY); // restore selection GDI32.SelectObject(hdcDest, hOld); // clean up GDI32.DeleteDC(hdcDest); User32.ReleaseDC(handle, hdcSrc); // get a .NET image object for it Image img = Image.FromHbitmap(hBitmap); // free up the Bitmap object GDI32.DeleteObject(hBitmap); return img; } </code></pre> <h2>Update</h2> <p>I am currently making use of PrintWindow which is the only thing that has come the closest as it manages to capture the window frame (i.e the minimise, maximise and close buttons) but the inner part is black.</p> <p>Although it hasn't fully worked, its proved to me that it is possible to create an image from a window handle whilst the application isn't even visible to a user.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload