I am creating a service using CreateService
. The service will run again fine if it happens to crash and I would like to have Windows restart the service if it crashes. I know it is possible to set this up from the services msc see below.
How can I programatically configure the service to always restart if it happens to crash.
You want to call ChangeServiceConfig2 after you've installed the service. Set the second parameter to
SERVICE_CONFIG_FAILURE_ACTIONS
and pass in an instance of SERVICE_FAILURE_ACTIONS as the third parameter, something like this:Used Deltanine's approach, but modified it a bit to be able to control each failure action:
The answer above will give you the gist... but it wont compile.
try: