如何使用" sc"安装服务并为"随后的失败指定NO ACTION"正在复苏

时间:2014-04-04 20:34:42

标签: service installation

我在VB.NET中创建了一个服务,并希望使用“sc”程序来安装它。 (我需要打包它,以便我组织中的其他人可以执行实际的安装。)

我希望“恢复”选项看起来如下:

  • 首次失败:重启
  • 第二次失败:重启
  • 后续失败:什么都不做

这是我最初尝试的命令(在实际安装之后):

sc failure MyServiceName reset= 86400 actions= restart/15000/restart/30000

但是随后在GUI中查看服务,“后续失败”也被设置为重新启动。我看着SO,找不到具体的东西。我最终想通了,我在这里发布这个以防万一其他人正在寻找同样的“快速”答案。当然,如果有人有任何贡献,我很乐意阅读。

2 个答案:

答案 0 :(得分:15)

我最终想到要运行这样的命令:

sc failure MyServiceName reset= 86400 actions= restart/15000/restart/30000//1000

一旦我这样做,并重新打开服务属性GUI,就会显示“不采取行动”,因为我希望它能够显示。

在我开始写这个问题之后,我终于找到了这个问题: https://stackoverflow.com/a/12631379/1812688

虽然,它并没有直接回答问题

答案 1 :(得分:8)

To expand on this answer, the sc command is stupidly finnicky, and you need to do a couple things:

  1. you must provide 'reset' and 'actions' at the same time
  2. you must have a space after each option, so reset= <number>, etc
  3. you cannot provide no options to 'action' (despite what the documentation on sc.exe claims),但您可以提供以斜杠分隔的空值。所有这三个命令都会使它完成3次尝试中的任何一次都没有动作
    • sc failure EraAgentSvc reset= 86400 actions= //
    • sc failure EraAgentSvc reset= 86400 actions= ////
    • sc failure EraAgentSvc reset= 86400 actions= //////
  4. 这些命令最终会得到&#39; sc qfailure&#39;的结果:

    C:\Users\Administrator>sc qfailure EraAgentSvc
    [SC] QueryServiceConfig2 SUCCESSSERVICE_NAME: EraAgentSvc
            RESET_PERIOD (in seconds)    : 86400
            REBOOT_MESSAGE               :
            COMMAND_LINE                 :
    
相关问题