开发者

Start a program in an active user session from a service? [duplicate]

开发者 https://www.devze.com 2022-12-11 14:27 出处:网络
This question already has answers here: 开发者_运维知识库 How to start a process from windows service into currently logged in user's session
This question already has answers here: 开发者_运维知识库 How to start a process from windows service into currently logged in user's session (8 answers) Closed 6 years ago.

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

Using Process.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.

0

精彩评论

暂无评论...
验证码 换一张
取 消