I want to change the properties of a service that I have running on my computer from a C# application.
What I want to do is, having a service installed already, change its Startup Type properties to Automatic (delayed start) and its recovery options (the first and second errors) to restart the service.
I have seen that when doing this:
ServiceInstaller serviceInstaller = new ServiceInstaller();
serviceInstaller.StartType = ServiceStartMode.Automatic;
//serviceInstaller.DelayedAutoStart //No me deja utilizar esta propiedad para el automático retrasado
You can tell it to set it to automatic, but not to a delayed start.
To install this service I do it with the InstallUtil utility through:
System.Diagnostics.ProcessStartInfo("InstallUtil ...");
If you call it using the command
sc start = delayed-auto
you can start the service automatically and delay.And for the control of the failure options you will have to use the command
SC failure
with which you can set the properties in case of failure.The documentation can be found here .
You could call all of this from the event directly invoking the CMD with the necessary commands
AfterInstall
.ProjectInstaller