Search code examples
c#.netwindows-servicesprocessscreenshot

Screenshot of process under Windows Service


We have to run a process from a windows service and get a screenshot from it.

We tried the BitBlt and PrintWindow Win32 calls, but both give blank (black) bitmaps.

If we run our code from a normal user process, it works just fine.

Is this something that is even possible? Or could there be another method to try?

Things we tried:

  1. Windows service running as Local System, runs process as Local System -> screenshot fails
  2. Windows service running as Administrator, runs process as Administrator -> screenshot fails.
  3. Windows application running as user XYZ, runs a process as XYZ -> screenshot works with both BitBlt or PrintWindow.
  4. Tried checking "Allow service to interact with desktop" from Local System

We also noticed that PrintWindow works better for our case, it works if the window is behind another window.

For other requirements, both the parent and child processes must be under the same user. We can't really use impersonation from one process to another.


Solution

  • I don't think this is possible.

    We had to change our scenario where our application wasn't started from a service, but was a standard windows program that has a NotifyIcon in the corner.

    If someone still finds a real answer, let me know.