次の方法で共有


Sc failure

 

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

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

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

Syntax

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

  • Not all services allow changes to their failure options. Some run as part of a service set.

  • To run a batch file when a service fails, specify command= Cmd.exe** **Drive:\FileName.bat, where Drive:\FileName.bat is the fully qualified name of the batch file.

  • To run a VBS file when a service fails, specify command= Cscript Drive:\MyScript.vbs, where Drive:\MyScript.vbs is the fully qualified name of the script file.

  • You can specify up to three separate actions with the actions= parameter, to be used the first, second, and third times that a service fails.

  • For each command-line option (parameter), the equal sign is part of the option name.

  • A space is required between an option and its value (for example, actions= restart). If the space is omitted, the operation will fail.

Examples

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

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