How can I have a service run a process under the current user's session?

假如想象 提交于 2019-12-25 08:53:18

问题


I have a service, written in C#, that monitors a set of files. It uses Growl to notify the end-user if the modified time of one of these files is over 4 hours old. I've seen situations where Growl.exe was not running under the current user's session, thus they did not receive updates. I'd like my service to check to make sure Growl is running (either Growl.exe or maybe I could look for the application ID somewhere?) and start it if it's not. How can I ensure that Growl is always running in the current user's session on any machine that this service runs on?


回答1:


If the service needs to run as the current user, then why make it a service? The purpose of a service is to run at all times, even when a user is not logged in. As such, it's designed to run as a specific user at all times.

Why not convert this to a program that runs when a user logs in?




回答2:


It's an interesting question, but it would appear that you can't do this as this post suggests. It seems like you can either specify that the service runs as a local system service, or as a particular user:




回答3:


If your service is being started as "automatic" then you may only pre-configure a single set of credentials for the service. However, if you can identify the .exe file that the service is invoking at startup then you can create a batch file that will kick off that service at logon, at which point the active users credentials will be used by default.

Cheers,

CEC



来源:https://stackoverflow.com/questions/5627404/how-can-i-have-a-service-run-a-process-under-the-current-users-session

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!