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

ngo*_*eff 8 c# screenshot remote-desktop

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

ari*_*iel 4

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