简体   繁体   中英

Use ServiceController to start a service with a different account

I'm using the ServiceController class to start a (custom) installed service, like this:

var newServiceController = new ServiceController("theNameOfMyService");
newServiceController.Start();

Trouble is, the service always runs under the local system account, and instead I want it to run under my account.

Can anyone tell me how to use ServiceController to run a service under a different account?

I don't think you can... the credentials for the service are provided at install time or alternatively via the Service.msc snap in

The service controller can only start/stop a pre-installed service

在为您服务的ServiceProcessInstaller实例上,有一个名为Acount,Password和Username的属性,可以使用这些属性来设置服务的运行对象。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM