2010-08-09 49 views
6

我有以下C#代码,我正在使用它捕获远程桌面(RDP)会话中的屏幕截图。它会在会话处于活动状态时正常工作,但如果我将会话最小化,则会导致无效句柄异常。捕获最小化远程桌面的屏幕截图

有什么办法可以做到这一点,或者当会话最小化时屏幕基本上“消失”了吗?

string filename = @"C:\Snap.png"; 
Size bitmapSize = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); 
using (Bitmap bitmap = new Bitmap(bitmapSize.Width, bitmapSize.Height, PixelFormat.Format24bppRgb)) 
using (Graphics graphics = Graphics.FromImage(bitmap)) 
{ 
    graphics.CopyFromScreen(// Exception thrown here 
     new Point(0, 0), 
     new Point(0, 0), 
     bitmapSize); 
    bitmap.Save(filename, ImageFormat.Png); 
} 
+0

程序是在远程机器还是本地机器上运行? – siride 2010-08-09 05:06:18

+0

它在远程机器上运行。 – ngoozeff 2010-08-09 05:16:05

回答

4

您必须临时恢复窗口,捕获并再次将其最小化。 This link shows how to do it silently

+0

如果我在客户端截取屏幕截图,这将起作用。我宁愿在远程会话中使用某些东西,但如果没有其他的东西出现,我会继续使用它。 – ngoozeff 2010-08-09 06:00:02