Sc failure


Applies To: Windows Server 2003 R2,Windows 7,Windows Server 2003 with SP2,Windows Server 2003,Windows Vista,Windows Server 2003 with SP1,Windows Server 2008,Windows Server 2008 R2

Specifies one or more actions to take if a service fails.

For examples of how to use this command, see Examples.

Syntax


Copy Code

sc [<ServerName>] failure [<ServiceName>] [reset= <ErrorFreePeriod>] [reboot= <BroadcastMessage>] [command= <CommandLine>] [actions= {"" | {[run/<MS>] | [restart/<MS>] | [reboot/<MS>]}[/...]]

Parameters

Parameter

Description

<ServerName>

Specifies the name of the remote server on which the service is located. The name must use the Universal Naming Convention (UNC) format (for example, \\myserver). To run SC.exe locally, omit this parameter.

<ServiceName>

Specifies the service name returned by the getkeyname operation.

reset= <ErrorFreePeriod>

Specifies the length of the period (in seconds) with no failures after which the failure count should be reset to 0 (zero). Note that this parameter requires the actions= parameter.

reboot= <BroadcastMessage>

Specifies the message to be broadcast when a service fails.

command= <CommandLine>

Specifies the command-line command to be run when the specified service fails. For more information about how to run a batch or VBS file on failure, see Remarks.

actions= {"" | {[run/<MS>] | [restart/<MS>] | [reboot/<MS>]}[/...]

Specifies one or more failure actions and their delay times (in milliseconds), separated by a forward slash (/). Valid actions are run, restart, and reboot. If more than one action is specified, each action must be separated by a forward slash. Use actions= "" to take no action a service fails. Note that this parameter requires the reset= parameter.

/?

Displays help at the command prompt.

Remarks

Examples

The following examples show how you can use the sc failure command:


Copy Code

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

Additional references

Command-Line Syntax Key