Windows service couldnt get screenshot in windows 7

北城以北 提交于 2019-11-26 10:01:12

问题


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?


回答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?

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.




回答2:


a windows service is designed to run also when there are no users connected, it works like a server process always up and listening, or up and doing something, or idle.

I think what you need is a client application which runs inside every logged user' session and eventually does the job then, if needed, communicates with the service to carry some job done.

I am saying here that instead of having the windows service running in another session than 0 you can create a small executable (probably with no UI at all) that starts up from the start up folder of all users at every user login. such application is then running inside the proper session and has access to it, it can get the screenshot then either store it somewhere itself or call some end points in your Windows Service (running always in session 0) and make the service to elaborate the screenshot taken from the client application of it.

this is the way I would do it, not trying some "magic" to tell Vista and 7 to start a service inside a session of a user that in the end is not logged in yet when the system starts.



来源:https://stackoverflow.com/questions/7454106/windows-service-couldnt-get-screenshot-in-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!