How do I set Service Config?

  • Thread starter Thread starter Ken Varn
  • Start date Start date
K

Ken Varn

Is there a class or method that can be called to set the configuration
settings of an existing Windows Service? In particular I want to set the
startup mode (i.e, Manual, AutoStart, etc..). I can do it with a pinvoke,
but I wanted to check first to see if there was a way to do it natively. I
noticed there is a ServiceController class, but in only allows checking of
the status, and not setting it.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
 
Ken said:
Is there a class or method that can be called to set the configuration
settings of an existing Windows Service? In particular I want to set
the startup mode (i.e, Manual, AutoStart, etc..). I can do it with a
pinvoke, but I wanted to check first to see if there was a way to do
it natively. I noticed there is a ServiceController class, but in
only allows checking of the status, and not setting it.

No, I don't believe there's any way to do this. You can alter some settings
using ServiceInstaller by uninstalling and reinstalling the service, but to
do this the service has to be stopped and you need sufficient rights to
install services (plus ServiceInstaller isn't intended to be invoked
directly). From within the service you can alter some things through
protected members of the ServiceBase class, but not any of the configuration
properties. I hope you'll consider wrapping your P/Invoke calls in a little
class library for reuse by others.
 
Back
Top