Screenshot of process under Windows Service

天涯浪子 提交于 2019-11-28 13:47:13

Currently i can't find the corresponding links, but the problem is, that a windows service runs in another session than a normal user application.

In XP this was not fully true. Here are all services started in Session 0 and the first user who logs into the system will also run in Session 0. So in that case, tricks like Allow service to interact with desktop work. But if you fast switch to another user he gets the Session 1 and has no chance to interact with the service directly. This is also true if you connect through RDP to a server version (like 2003 or 2008). These logins will also start in a session higher than 0.

Last but not least there is another drawback by using the interaction with the desktop:
If you enable this option and your service is running under the (default) SYSTEM account it won't be able to create a network connection anymore.

The correct way to get a custom GUI that works with a service is to separate them into two processes and do some kind of IPC (inter process communication). So the service will startup when the machine comes up and a GUI application will be started in the user session. In that case the GUI can create a screenshot, send it to the service and the service can do with it, whatever you like.

Have you tried to run as Local System with the "Allow service to interact with desktop" checked?

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.

It works using Local System with the "Allow service to interact with desktop"

You can set it programatically using this sample code:

http://www.vbforums.com/showthread.php?t=367177 (it's vb.net but very simple)

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