Search code examples
c#windows-servicessession-0-isolation

Windows service couldnt get screenshot in windows 7


I have a windows service which gets the screenshots. But its creating only black screens. I know this happens because of session 0 isolation. I searched on internet and couldnt find any approved solution for this problem any working ideas will be really good.

1- Is there a way to change the session of a windows service and get the desktop screen of another user's session like session 1, session 2?

2- Is there a way to start a console application which runs in an another session other than session 0 from a windows service?


Solution

  • Is there a way to change the session of a windows service and get the desktop screen of another user's session like session 1, session 2?

    No.

    Is there a way to start a console application which runs in an another session other than session 0 from a windows service?

    This can be done but it's messy. It involves impersonation of the logged on user, manipulation of user tokens, and launching a process into a different session with CreateProcessAsUser(). This article describes what is needed.

    As an aside, you don't want a console application because that will splat a console window on your screenshot. You just want a standard Windows app (using the GUI subsystem) but one that does not show any visible windows.