Question : Is there a way to make “ShellExecuteEx()” work from a Windows Service application?

We’ve been using “ShellExecuteEx()” to launch another process (non-console, visible GUI) from our application.   Now we have a need to run the application in a Windows service, and “ShellExecuteEx() doesn’t work (probably because of the “shell” part).  Is there a way to make “ShellExecuteEx()” work, or is there another way to launch a non-console process from within a service?  We’re working in C++.

Answer : Is there a way to make “ShellExecuteEx()” work from a Windows Service application?

@rgautier: Your advice is obsolete and no longer supported by MS.
Starting from Windows Vista, Interactive Services are only for compatibility reason and should not be enabled for new services.
In Vista and newer, services and logged on users reside always in different terminal session and thus only IPC is possible (so no handles, window messages and GUIs are possible). Vista and newer will display a nasty warning message if you try to show a dialog in a service.

Instead you have to create a new process in the target session (starts at 1), where you want to run your application. Use CreateProcessAsUser (CPAU) but NOT CreateProcess.  Retrieve the user token with WTSQueryUserToken and use it in CPAU then.
Random Solutions  
 
programming4us programming4us