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_ACTIONSand pass in an instance of SERVICE_FAILURE_ACTIONS as the third parameter, something like this: