Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use "sc" to install a service and specify NO ACTION for "subsequent failures" under recovery

I created a service in VB.NET and wanted to use the "sc" program to install it. (I needed to package it so that someone else in my organization could perform the actual install.)

I wanted the "Recovery" options to look as follows:

  • First Failure: Restart
  • Second Failure: Restart
  • Subsequent Failures: Do Nothing

This is the command I initially attempted (after the actual install):

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

But then looking at the service in the GUI, "Subsequent Failures" was also set to restart. I looked on SO and couldn't find anything specific. I eventually figured it out, and I am posting this here in case anyone else is looking for the same "quick" answer I was. And of course, if anyone has anything to contribute, I would love to read it.

like image 545
StevoInco Avatar asked Apr 04 '14 20:04

StevoInco


2 Answers

I eventually figured out to run the command like this:

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

Once I did this, and re-openned the service properties GUI, "Take no action" was shown as I wanted it to be.

After I started writing the question, I did finally find this SO question: https://stackoverflow.com/a/12631379/1812688

Although, it wasn't in direct response to the question

like image 69
StevoInco Avatar answered Sep 20 '22 11:09

StevoInco


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), but you can provide empty values separated by a slash. All of these 3 commands will make it so there are no actions for any of the 3 attempts
    • sc failure EraAgentSvc reset= 86400 actions= //
    • sc failure EraAgentSvc reset= 86400 actions= ////
    • sc failure EraAgentSvc reset= 86400 actions= //////

and those commands will end up with the result from 'sc qfailure':

C:\Users\Administrator>sc qfailure EraAgentSvc
[SC] QueryServiceConfig2 SUCCESSSERVICE_NAME: EraAgentSvc
        RESET_PERIOD (in seconds)    : 86400
        REBOOT_MESSAGE               :
        COMMAND_LINE                 :
like image 36
mgrandi Avatar answered Sep 22 '22 11:09

mgrandi