Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capturing screenshots of a minimized remote desktop

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);
}
like image 576
ngoozeff Avatar asked Aug 09 '10 05:08

ngoozeff


People also ask

How do I take a screenshot when connected to remote desktop?

“Ctrl” + “Alt” + “-”: This command takes a screenshot of the active window on the host computer's screen, saving it to the guest computer.

How do I take a screenshot on an adjusted window?

Press Windows+Shift+S to open the Snipping Tool. 2. Select what type of screenshot you want from the Mode menu. Click the 'Mode' button on the Snipping Tool to open a drop-down menu and select from the various different types of screenshots, from full-screen to just a selected portion.

How do you screenshot on a workspace?

Use Windows key + PrtSc key to take a full screen screenshot and save it to your computer. Similar to the PrtSc key windows key, hitting the Windows key + Print Scren keys will grab a screenshot of your entire desktop but only on an active window.


1 Answers

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

like image 132
ariel Avatar answered Oct 03 '22 20:10

ariel