Get notified when a service fails

Post image for Get notified when a service fails

by Steve Wiseman on January 5, 2010 · 2 comments

in Command Line, Tips, Tools, Utility

No matter what company I have worked for, there is always a Windows service that crashes once in a while – like clock work.

The problem: The service that crashes is important, does real time processing, and must always be active.

I came up with a quick and easy way of getting notified when your favorite service crashes.

First, you will need a copy of the free tool called blat. You can get a copy of it here:

Blat command line emailer

Download it, and copy it to a place on the server that is easy for your batch files to find.

Next, we will need to set up a batch file that will create and send out our email with blat. For my example, I am going to get a notification each time the print spooler crashes (Because of a buggy print driver)…so I want my email to tell me that the print spooler crashed.

Here is what the batch file would look like:

blat -subject "Spooler Crashed again" -body "Go fix the printer...the spooler crashed again!" -to support@intelliadmin.com -from alert@intelliadmin.com

This email will have a subject of “Spooler Crashed again” and a body of “Go fix the printer…the spooler crashed again!”. Some of you wise guys may be saying, “just set that service to restart, and you don’t even have to touch it!”

Unfortunately when the spooler crashes, a helper process is still stuck in the background…and it will crash the spooler until you kill it.

Save the batch file in a place you can easily find it. I am going to call mine “scnotify.bat”. Run it from the command line once and make sure it is working properly.

Now, go into the service list (Click start then run, and type services.msc..and hit OK). Find your ‘problem’ service, and right click on it – go to properties.

Service List

A window will show. Move over to the recovery tab, and select the drop down for the first failure. Pick the “run a program” option:

Service Properties

Once you do that, the options for the application will become enabled. Select your batch file that you created before:

Select Application

That is all there is to it. Now when that critical service crashes, you will know right away.

{ 2 comments… read them below or add one }

bavness January 8, 2010 at 10:29 am

nice one steve

RJW van den Hout February 5, 2010 at 9:29 am

Hi Steve,

I tried to implant this on a server running a iMail mail server, the IMail Queue Manager Service fails from time to time and i like to be informed whenever this happens. Recently this error occurred again but the notify.cmd batch file was never run.
The service runs under the ‘Local System’ account, and apparently the seems to be a permission issue when calling the batch script.

The eventlog shows:
“The Service Control Manager tried to take a corrective action (Run the configured recovery program) after the unexpected termination of the IMail Queue Manager Service service, but this action failed with the following error: Access is denied.”

Do you know how i can fix this?
The file permission on notify.cmd are:
Administrators / System (both full control) and Users (read, read & execute)

Leave a Comment

Previous post:

Next post: