ProblemYou want to perform an action automatically when a service fails. SolutionUsing a graphical user interface
Using a command-line interfaceThe following command causes the MyMonitor service to be automatically restarted after two failures and then reboots on the third failure. Each failure can be up to 5 seconds apart: > sc failure MyMonitor reset= 3600 reboot="Restarting do to repeated MyMonitor failure" actions= restart/5000/restart/5000/reboot/5000 Using VBScriptThe Win32_Service class does not support setting the recovery options for a service. DiscussionWindows 2000 added a new capability that was sorely missing in previous versions: the ability to automatically perform an action when a service fails. You can configure an action to occur after the first failure, second failure, or subsequent failures. The actions you can take include no action (the default), restarting the service, running a program, or restarting the computer. You can also reset the failure count after a certain number of days. So let's say that you want to have a service restart itself after a failure, but no more than once a day. You would configure the first failure action to restart the service and set the reset fail count to one day. You can also combine multiple actions by choosing to run a program after service failure. You can create a simple batch file that restarts the service and emails you a report. This gives you a lot of flexibility in how you handle service failures. |