windows服务失败选项的命令处理




对于服务失败的处理命令:

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


 

ParameterDescription

<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.

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.

command remark      


  • 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.exeDrive:\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=CscriptDrive:\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.

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值