I need to change the credentials of an already existing Windows service using C#. I am aware of two different ways of doing this.
- ChangeServiceConfig, see ChangeServiceConfig on pinvoke.net
- ManagementObject.InvokeMethod using Change as the method name.
Neither seems a very "friendly" way of doing this and I was wondering if I am missing another and better way to do this.
ChangeServiceConfig is the way that I've done it in the past. WMI can be a bit flaky and I only ever want to use it when I have no other option, especially when going to a remote computer.
Here is one quick and dirty method using the System.Management classes.