I have done a lot of searching to find a way to start a GUI application from a windows service on Windows 7. Most of what I have found is that with Windows 7 services now run in a separate user session and can not display any graphical interface to the current user. I'm wondering is there is any kind of workaround or different way of accomplishing something like this? Can the service start a process in a different user session?
-
why not write a windows application, scheduled by windows scheduler – Adeel Feb 21 '11 at 08:32
3 Answers
This change was made for a reason and not simply to annoy developers. The correct approach is to put your UI in a different program and communicate with the session through a pipe, or some other IPC mechanism. The recommendation that services do not present UI is more than 10 years old now.
You should really try to follow these rules, even though it may seem inconvenient to begin with. On the plus side you will enjoy the benefit of keeping your service logic and UI logic separate
If your services runs under the LOCALSYSTEM account then you can check "Allow service to interact with desktop", for the benefit of legacy services that would fail if they could not show UI. But it won't help you anyway because the UI will show in session 0 where it is never seen!
I recommend you take a read of the official Microsoft document describing session 0 isolation.

- 523
- 4
- 14

- 601,492
- 42
- 1,072
- 1,490
-
-
Yes, thank you. I already have a management application that interacts with the service via a tcp connection. I can just send a message to the management application to execute the command line. Only problem is is the user closes the management app, the service wont be able to execute the command line commands. – Brian Feb 21 '11 at 23:35
-
2So does this mean that one should not start the UI from the service and therefore needs to put the UI program in the autostart in addition to the service being started automatically? – Taxel Jul 26 '18 at 15:38
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 a complex UI elements you can put it in a separate program and you need to use CreateProcessAsUser Routine. In this sample provided by microsoft you can see the process.
http://blogs.msdn.com/b/codefx/archive/2010/11/26/all-in-one-windows-service-code-samples.aspx

- 2,536
- 1
- 20
- 22
-
1The [CppInteractiveWindowsService sample](http://code.msdn.microsoft.com/CppInteractiveWindowsServic-c241d080) has the relevant code in [SampleService.cpp](https://code.msdn.microsoft.com/CppInteractiveWindowsServic-c241d080/sourcecode?fileId=20438&pathId=2122997860). – Joel V. Earnest-DeYoung Aug 06 '18 at 08:21
Windows 7 introduced what is called "Session 0 isolation" that in practice means that every service (except system services) run in a separate non-interactive session. For this reason you cannot directly create a GUI from within the service, except if you run in legacy mode by flagging the Interact With Destop option, which is not good if you plan to run your service for some years in the future.
As David Heffernan said, the best is to use a client-server architecture. WCF makes it easy to communicate with named pipes.
This page is a good starting point to read about Session 0 Isolation and this white paper is also very good.

- 9,100
- 6
- 33
- 43