Start a program in an active user session from a service? [duplicate]
How can I start a program in an active user session from a running .NET background process. Basically I have a .NET application running as a service and I want that application to launch a specific windowed application on the users desktop when certain events happen.
How can I do this?
This question is related to this one: Start a program in active user session with PowerShell remoting
Update
UsingProcess.Start
alone will not work here since it launches the application in the current application session. It doesn't launch the application in a specific users active desktop session.Is it feasible for you to build some kind of lightweight listener application that the user would run in the background? Presumably your service could communicate with the listener and have the listener instantiate the windowed app since it's running in the user's context.
The CreateProcessWithLogonW function will allow you to pass in the credentials of the user you want the application to run as.
Also, note that if you go down this route you do need to pass in the STARTUPINFO structure so that it starts on the right desktop, and not just leave it null.
Look into the Log On context of the windows service as shown here. This allows interaction of the windows service with a desktop session.
精彩评论