Note that there are some explanatory texts on larger screens.

plurals
  1. POCapture screen on server desktop session
    primarykey
    data
    text
    <p>I have developed a GUI test framework that does integrationtesting of our company website on a scheduled basis. When something fails, it'll take a screenshot of the desktop, among other things. This runs unattended on a logged in user on a dedicated Windows Server 2008.</p> <p><strong>The problem</strong> is that taking a screenshot on a desktop that I have disconnected my remote desktop session from. I get the following exception:</p> <pre><code>System.ComponentModel.Win32Exception (0x80004005): The handle is invalid at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation) at System.Drawing.Graphics.CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize) at IntegrationTester.TestCaseRunner.TakeScreenshot(String name) in C:\VS2010\IntegrationTester\IntegrationTester\Config\TestCaseRunner.cs:line 144 at IntegrationTester.TestCaseRunner.StartTest() in C:\VS2010\IntegrationTester\IntegrationTester\Config\TestCaseRunner.cs:line 96 </code></pre> <p>The <strong>TakeScreenshot()</strong> method looks like this:</p> <pre><code>public static void TakeScreenshot(string name) { var bounds = Screen.GetBounds(Point.Empty); using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height)) { using (Graphics g = Graphics.FromImage(bitmap)) { g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size); } bitmap.Save("someFileName", ImageFormat.Jpeg); } } </code></pre> <p>I have made sure that screensaver is set to "None" with no timeout. I have also implemented a piece of code that does a couple of pinvokes to <strong>send a mouse move</strong>, hoping it would generate a desktop graphics handle.. but no.</p> <pre><code>IntPtr hWnd = GetForegroundWindow(); if (hWnd != IntPtr.Zero) SendMessage(hWnd, 0x200, IntPtr.Zero, IntPtr.Zero); </code></pre> <p>Any advice is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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