13

I have installed many of our custom written services on windows boxes (does not matter if XP, Server, Vista). I always configure to "Restart the Service" on 1st, 2nd and subsequent failures. But I have never seen this work; the service simply stops (because of an error or something in the code) but does not restart.

I just noticed the "Enable Actions For Stops With Errors" checkbox. Does this have to be checked in order for the recovery to take affect if the failure was caused by an error?

thanks, Mark.

2 Answers 2

7

If your services are stopping because of an error, that is logged by windows then yes, you need to tick 'Enable Actions For Stops With Errors', otherwise it will not work.

If you do not have this ticked, then it will only restart services that have stopped for legitimate or unknown reasons.

You can also do it with commandline:

 sc.exe failureflag [MyService] 1
8
  • 1
    Thanks - I kind of figured that. But I would have thought "Error" would be the same thing as a "failure", and hence the service should have started without checking the box.
    – M Schenkel
    Oct 9, 2009 at 2:18
  • It does seem a little odd I agree, as most of the reasons a service would fail you would think would be an error.
    – Sam Cogan
    Oct 9, 2009 at 8:33
  • 3
    No recovery action is ever to be triggered on services that have stopped for "legitimate" reasons. This answer still makes confusion upon "stop" and "failure" terms.
    – matpop
    Oct 7, 2014 at 14:57
  • 5
    Whomever at Microsoft that penned this language should be endlessly flogged for their incompetence.
    – Brain2000
    Jan 29, 2016 at 21:28
  • 1
    If a service exists without an exit code, or with a 0 exit code then this is not a crash as far as Windows is concerned, it has just exited, and it will restart. If the exit code is >0 then this indicates it stopped with an error and will not be restarted without this tick box being checked.
    – Sam Cogan
    Feb 11, 2021 at 14:26
25

The "Enable actions for stops with errors" checkbox was introduced with Windows Vista and Windows Server 2008, providing a single, embarrassing line of documentation:

Select Enable actions for stops with errors in order to trigger the recovery actions that the service stopped with an error.

The SC.exe program was also updated to provide a new command: failureflag. The documentation shows a bad example and doesn't really apply to Windows Server 2003, but tells us that the command:

Specifies whether recovery actions will be triggered when a service stops as the result of an error.

So, the checkbox and sc failureflag are used to set the same flag.
Let's type sc failureflag in the command prompt, we finally get a quite decent description:

Changes the failure actions flag setting of a service. If this setting is 0 (default), the Service Control Manager (SCM) enables configured failure actions on the service only if the service process terminates with the service in a state other than SERVICE_STOPPED. If this setting is 1, the SCM enables configured failure actions on the service if the service enters the SERVICE_STOPPED state with a Win32 exit code other than 0 in addition to the service process termination as above. This setting is ignored if the service does not have any failure actions configured.

A similar description can be found here.
So, the correct answer to the original question is: the configured recovery actions always take effect when your service doesn't terminate in the SERVICE_STOPPED state. "Enable actions for stops with errors" must be checked if you need to enable the recovery actions also when your service enters the SERVICE_STOPPED state, provided that the exit code is not 0 (error).

2
  • 3
    Kudos for a very helpful answer! Apr 21, 2017 at 19:58
  • 1
    This answer is 1000% better than the accepted answer.
    – steve
    Feb 10, 2021 at 12:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .