相关疑难解决方法(0)

在服务器桌面会话上捕获屏幕

我开发了一个GUI测试框架,可以按计划对我们公司网站进行集成测试.当某些内容失败时,它会截取桌面的屏幕截图等.这在专用Windows Server 2008上的登录用户上无人值守.

问题是在我已断开远程桌面会话的桌面上截取屏幕截图.我得到以下异常:

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
Run Code Online (Sandbox Code Playgroud)

TakeScreenshot()方法是这样的:

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);
            }
        }
Run Code Online (Sandbox Code Playgroud)

我确保屏幕保护程序设置为"无",没有超时.我还实现了一段代码,它可以执行一些pinvokes来发送鼠标移动,希望它能生成桌面图形处理..但是没有. …

.net c# pinvoke system.drawing windows-server-2008

19
推荐指数
2
解决办法
1万
查看次数

标签 统计

.net ×1

c# ×1

pinvoke ×1

system.drawing ×1

windows-server-2008 ×1