Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to monitor some third party software that runs several services on Windows. I simply want to set it up so that I get an email if the service restarts, fails, etc.

Is this something that can be easily scripted? Does someone have something basic for this task?

share|improve this question
up vote 2 down vote accepted

This is a bit ugly, but you could probably modify it to suit your needs. Just set up a scheduled task to call the script every so often.

Dim ServiceDown
Dim Message

Function sGetServiceStatus(ByVal strServiceName)
    wbemImpersonationLevelImpersonate = 3
    wbemAuthenticationLevelPktPrivacy = 6

    Set objLocator = CreateObject("WbemScripting.SWbemLocator")
    Set objWMIService = objLocator.ConnectServer("localhost")

    objWMIService.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate
    objWMIService.Security_.AuthenticationLevel = wbemAuthenticationLevelPktPrivacy

    Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where DisplayName ='"& strServiceName & "'")

    if(colListOfServices.Count=0) then
        sGetServiceStatus = ""
        Exit function
    end if

    For Each objItem in colListOfServices
        If objItem.DisplayName = strServiceName and objItem.State = "Running" Then
            sGetServiceStatus = objItem.State                       
            Exit Function
            sGetServiceStatus = objItem.State
            ServiceDown = True
            Message = Message & vbcrlf & strServiceName
            Exit function
        End If

    sGetServiceStatus = ""
End Function

sGetServiceStatus("ISC BIND")

If ServiceDown Then     
    Set objMessage = CreateObject("CDO.Message") 
    objMessage.Subject = "Check Services" 
    objMessage.From = "" 
    objMessage.To = "" 
    objMessage.TextBody = "The following service(s) is/are down: " & Message
End If
share|improve this answer
thanks, i will definitely try this out.. – jdamae Jul 30 '11 at 1:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.