Domanda

I want to pull credentials for a service from a database (be more dynamic)

I am using sc.exe to change the credentials inside OnStart before I call .Start() on the service.
The sc.exe change works, but I noticed it doesn't take effect until after I restart again.

i.e. I notice it's SYSTEM as the user it's running as. Once I restart again its showing my domain account.

Is there any other way to change the Credentials that would allow me to do it inside OnStart before it actually runs?

Thanks, David

È stato utile?

Soluzione

Is there any other way to change the Credentials that would allow me to do it inside OnStart before it actually runs?

No. When OnStart is executed the service does actually run so whatever you do, it'll be too late.

Setting the credentials, and other things like start type, command line, dependencies, etc., should be considered a setup/installation/registration task.

You could probably conceive some (rather complicated) bootstrapping mechanism, like one service starting another before updating its credentials. I would really ask myself if that is all worth it though.

A service that "dynamically" changes its user also seems pretty unpredictable from a system operations / administrations point of view.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top