How do I make a service stopping trigger an e-mail?

I am trying to set up an auto email when a specific service stops.
seanwebAsked:
Who is Participating?
 
Elwin3Commented:
Got to the service and look at the properties. on the recovery tab on failure set to run a program. Then create a vbs script using the following code (changing the bits in bold) and then run that on failure:

Set objEmail = CreateObject("CDO.Message")

objEmail.From = "myname@myemail.co.uk"
objEmail.To = "goingto@myemail.co.uk"
objEmail.Subject = "Server down"
objEmail.Textbody = "Server1 is no longer accessible over the network."
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
        "mysmtpsmarthost"
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
0
 
seanwebAuthor Commented:
That's great thanks, how can I test it though? As stopping the service manually I would guess is not picked up as a failure, right?
0
 
seanwebAuthor Commented:
Also, I assume that writing this out on notepad and saving as a .vbs file is adequate, yes?
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
Elwin3Commented:
yes thats right just save as .vbs

a bit tricky to test I agree. You can obviously test the script on it's own.
0
 
seanwebAuthor Commented:
Thanks, I have tested the script and have an error on line 15, anything you can see?
0
 
Elwin3Commented:
what smartshost did you enter in the script. For example - I use a ISP called plusnet so my smarthost is relay.plus.net but rememebr this must be the smarthost of the line you are going out off.

 
0
 
seanwebAuthor Commented:
AhHa! Missed that, working perfectly now, thank you very much.
0
 
seanwebAuthor Commented:
Great script, very useful, took no time at all.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.