Hello, I need a way to enable or disable an windows service programmatically, with .Net if possible.
Actually, I found a way to do it with sc.exe (from the resource kit):
sc config [ServiceName] start= demand (for manual or auto for automatic)
So I can just run that command.
But I would prefer finding another way than runing an external command.
It's already possible to control the services via the ServiceController class, but apparently not changing the startupType.
A call to an API would be ok if there's no such class.
I have also tried by editing the registry, but it seem the changes are not completely taken into account
(0x00000000 = Boot
0x00000001 = System
0x00000002 = Automatic
0x00000003 = Manual
0x00000004 = Disable
but altough it seem to work when looking in the services manager, I still could not start the service after I changed those values.
(To check, disable a service via the service manager, change the value with regedit, if you refresh the manager, the startup type seem changed, but the service wont start as if still disabled)
So maybe if someone knows why the change is not immediate, and how to force it, it would also be ok.
Thanks for any help.