You can use the sc command-line tool to query a service and configure it to restart automatically when it fails.
Query a service's failure configuration using 'sc qfailure':
sc qfailure <ServiceName>
Specify that recovery actions will be triggered when a service stops as the result of an error using 'sc failureflag':
sc failureflag <ServiceName> flag=1
Set one or more recovery actions after a failure using 'sc failure':
sc failure <ServiceName> [reset= <ErrorFreePeriod>] [reboot= <BroadcastMessage>] [command= <CommandLine>] [actions= {"" | {[run/<MS>] | [restart/<MS>] | [reboot/<MS>]}[/...]]
Here are some examples that I borrowed from Microsoft Learn:
sc failure msftpsvc reset= 30 actions= restart/5000
sc failure dfs reset= 60 command= c:\windows\services\restart_dfs.exe actions= run/5000
sc failure dfs reset= 60 actions= reboot/30000
sc failure dfs reset= 60 reboot= "The Distributed File System service has failed. Because of this, the computer will reboot in 30 seconds." actions= reboot/30000
sc failure myservice reset= 3600 reboot= "MyService crashed -- rebooting machine" command= "%windir%\MyServiceRecovery.exe" actions= restart/5000/run/10000/reboot/60000
The full documentation for sc failure
is in the "previous versions" area of Microsoft Learn at this link.