views:

532

answers:

2

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?

+2  A: 

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

Eoin Campbell
A: 

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.

CSharpAtl