7.6. Performing an Action Automatically When a Service Fails


You want to perform an action automatically when a service fails.


Using a graphical user interface

  1. Open the Services snap-in.

  2. In the left pane, double-click on the service you want to configure.

  3. Click the Recovery tab.

  4. Configure the failure options you want and click OK.

Using a command-line interface:

The following command causes the MyMonitor service to automatically restart after two failures and reboot on the third. Each failure can be up to five seconds apart.

> sc failure MyMonitor reset= 3600 reboot="Restarting due to repeated MyMonitor
failure" actions= restart/5000/restart/5000/reboot/5000

Using VBScript

The Win32_Service class does not support setting the recovery options of a service.


Windows 2000 added a new capability that was sorely missing in previous versions of Windows: the ability to automatically perform a specified action when a service fails. You can configure an action to occur after the first, second, and subsequent failures. The actions you can take include no action (the default), restarting the service, running a program, or restarting the computer. Restarting the service or computer should be used as a last resort because they could mask underlying problems.

You can also reset the failure count after a certain number of days. So let's say that you have a service that regularly fails multiple times a day, but you only want it to restart itself after the first failure every day. ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.