Is there a way to run a GUI application from a Windows service on Windows 7?

I searched a lot to find a way to start a GUI application from a Windows service on Windows 7. Most of what I discovered is that Windows 7 services now work in a separate user session and cannot display any graphical interface for the current user. I am wondering if there are any workarounds or another way to accomplish something like that? Can a service start a process in a different user session?

+7
c # windows windows-services
source share
3 answers

This change was made for some reason, and not just to annoy developers. The right approach is to put your user interface in another program and communicate with the session through a channel or some other IPC mechanism. The recommendation that services do not provide a user interface is more than 10 years.

You really should try to follow these rules, even if it may seem inconvenient to start with. On the positive side, you will take advantage of keeping the service logic and user interface logic separate

If your services run under the LOCALSYSTEM account, you can check "Allow the service to interact with the desktop" for older services that fail if they cannot display the user interface. But it still will not help you, because the user interface will appear in session 0, where it has never been seen!

I recommend that you read the official Microsoft document describing session isolation 0 .

+16
source share

Windows 7 introduced the so-called "session isolation 0", which in practice means that each service (except system services) is launched in a separate non-interactive session. For this reason, you cannot directly create a graphical interface inside the service, unless you start in obsolete mode by checking the Interact With Destop option, which is not very good if you plan to use your service for several years.

As David Heffernan said, it is best to use a client-server architecture. WCF makes it easy to interact with named pipes.

This page is a good starting point to read about session isolation 0 and this white paper is also very good.

+1
source share

There is a way to do this. If you need to show a simple message box, you can use the WTSSendMessage Routine. If you need complex user interface elements, you can put it in a separate program, and you need to use CreateProcessAsUser Routine. In this example, presented by microsoft, you can see this process.

http://blogs.msdn.com/b/codefx/archive/2010/11/26/all-in-one-windows-service-code-samples.aspx

0
source share

All Articles