Configure Windows Service Recovery Options from Command-Line

Markus Kolbeck
Markus' Blog
Published in
1 min readAug 7, 2016

Configure Windows Service Recovery Options from Command-Line with the Service Control Manager tool SC.exe

Read the Configuration

The SC tool displays the Recovery Information using the syntax sc qfailure “Service Name”.

C:\Windows\System32>sc qfailure MSSQLSERVER
[SC] QueryServiceConfig2 SUCCESS
SERVICE_NAME: MSSQLSERVER
RESET_PERIOD (in seconds) : 0
REBOOT_MESSAGE :
COMMAND_LINE : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\AT\MyPowerShellScript.ps1 possibleArguments
FAILURE_ACTIONS : RESTART -- Delay = 60000 milliseconds.
RESTART -- Delay = 60000 milliseconds.
RUN PROCESS -- Delay = 1000 milliseconds.

Write the Configuration

To write the configuration, you can use the following example that also includes possible command line parameters and additional arguments for the powershell script to be executed.

SC failure MSSQLSERVER reset=0 actions=restart/60000/restart/60000/run/1000
sc failure MSSQLSERVER command= ""C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "C:\AT\MyPowerShellScript.ps1" "possibleArguments""
Windows Service - Recovery Options

The documentation of SC.exe can be found on TechNet

--

--