捕获最小化的远程桌面的屏幕截图

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

是否有任何方法可以使这项工作,或者当会话最小化时屏幕基本上“消失了”?

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); } 

您必须暂时恢复窗口,捕获并再次将其最小化。 此链接显示如何以静默方式执行此操作