Capturing screenshots of a minimized remote desktop
Asked Answered
D

1

8

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);
}
Dumanian answered 9/8, 2010 at 5:1 Comment(2)
Is the program running on the remote machine or the local machine?Hae
It's running on the remote machine.Dumanian
R
4

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

Renatarenate answered 9/8, 2010 at 5:9 Comment(1)
That works if I take the screenshot on the client. I would prefer something that works inside the remote session, but I will go with this if nothing else comes up.Dumanian

© 2022 - 2024 — McMap. All rights reserved.