Capturing screenshots of a minimized remote deskto

2019-02-12 22:27发布

I have the following C# code, which I am using to capture a screenshot inside a remote desktop (RDP) session. It works fine when the session is active, but fails with an invalid handle exception if I minimize the session.

Is there any way to make this work, or is the screen essentially "gone" when the session is minimized?

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

1条回答
等我变得足够好
2楼-- · 2019-02-12 23:09

You have to temporarily restore the window, capture, and minimize it again. This link shows how to do it silently

查看更多
登录 后发表回答