开发者

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

开发者 https://www.devze.com 2023-02-23 13:30 出处:网络
I have a service, written in C#, that monitors a set of files. It uses Growl to notify the end-user开发者_如何学JAVA if the modified time of one of these files is over 4 hours old. I\'ve seen situatio

I have a service, written in C#, that monitors a set of files. It uses Growl to notify the end-user开发者_如何学JAVA 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?


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?


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:

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


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

0

精彩评论

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

关注公众号