Ryan Lundy
Ryan Lundy

Reputation: 210080

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?

Upvotes: 0

Views: 2697

Answers (2)

CSharpAtl
CSharpAtl

Reputation: 7512

On the ServiceProcessInstaller instance for you service there is a property called Acount, Password and Username, can use these properties to set who the service runs as.

Upvotes: 0

Eoin Campbell
Eoin Campbell

Reputation: 44268

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

Upvotes: 3

Related Questions