How to exactly copy what you see on your screen?

Viewed 149

So I have searched for a while on how can you copy what's on your screen or take a screenshot, and I have found some solutions for example this method:

public static Bitmap TakeScreenshot()
{
  Bitmap newImg = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
  Graphics graphics = Graphics.FromImage(newImg as Image);
  graphics.CopyFromScreen(0, 0, 0, 0, newImg.Size);
  return newImg;
}

This method works fine, except that when you run an application as administrator, the screen shows something like "Are you sure? YES NO":

Run as Adminstrator

Or even on CTRL + ALT + DEL:

ctrl+alt+del

At these screens, these methods don't work as they will show a black screen, Also, some applications will give a black screen on them as they are like protected/not on your screen while other things on the screen appear normally.

Why is this happening? and how do I get what am I looking at EXACTLY on my screen?

EDIT #1:

Solution found using PsExec. (Thanks to Koray Elbek)

But still didn't fix the problem that happens with some applications as they will have a black box on them like this:

blackbox

Why is this happening and how to get the correct screenshot?

1 Answers

The following quote is from here

The logon screen is an isolated desktop running under NT_AUTHORITY\SYSTEM where you don't have access. To be able to use GUI on such private environment there are some shortcuts like this, but the definitive tool is PsExec It uses a service helper to run programs on a remote machine, or on a local machine as NT_AUTHORITY\SYSTEM. The helper service opens a named pipe to communicate with local application to get commands and return status. PsExec is not redistribuitable and sources are not available, but exists an open version called PaExec. You can download it and have a look... You should use PaExec to launch your app under NT_AUTHORITY\SYSTEM to have access to the DC of logon screen and capture images. But as I said this is an isolated DC so to catch snapshots from user screen and system screen you have to run 2 instances of your app.

This answer was posted for a C++ question, but the principles are same for you also, you will need to use same approach for your C# application too.

Related