Announcement

Collapse
No announcement yet.

Email when a service falls over

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Email when a service falls over

    Hello

    I mod this scripts to check an service on a remore computer, This scripts keeps falling over, Could I somehow get this to email myself?. I have look at the windows server 2008 triggers but did not work eith

    Code:
    Option explicit
    Dim strComputer,strServiceName
    
    strComputer = "192.168.1.16" ' Local Computer
    strServiceName = "masage200" ' K3 Service
    
    if isServiceRunning(strComputer,strServiceName) then
      wscript.echo "The '" & strServiceName & "' service is running on '" & strcomputer & "'"
    else
      wscript.echo "The '" & strServiceName & "' service is NOT running on '" & strcomputer & "'"
    end if
    
    ' Function to check if a service is running on a given computer
    function isServiceRunning(strComputer,strServiceName)
     Dim objWMIService, strWMIQuery
     strWMIQuery = "Select * from Win32_Service Where Name = '" & strServiceName & "' and state='Running'"
     Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     if objWMIService.ExecQuery(strWMIQuery).Count > 0 then
      isServiceRunning = true
     else
      isServiceRunning = false
     end if
    end function
    Last edited by Rems; 23rd February 2012, 20:51.

  • #2
    Re: Email when a service falls over

    I have founded this

    strComputer = "."
    strService = "Symantec Antivirus"

    Set objEmail = CreateObject("CDO.Message")
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Service where DisplayName = '" & Service & "'")
    For Each objItem in colItems
    If objItem.status <>"OK" or objItem.state <>"Running" then
    objEmail.From = "[email protected]"
    objEmail.To = "[email protected]"
    objEmail.Subject = "Antivirus State"
    objEmail.Textbody = objItem.DisplayName & " on: " & strComputer _
    '" State: " & objItem.State & VbCrLf
    objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
    "smtp.work.com"
    objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send
    End If
    Next

    The question what does http://schemas.microsoft.com/cdo/con...tion/sendusing DO?
    http://schemas.microsoft.com/cdo/con...ion/smtpserver D0?

    Comment


    • #3
      Re: Email when a service falls over

      CDO uses the MAPI library to send an email basically.
      simplest form of it is this:

      Code:
      Set objMessage = CreateObject("CDO.Message")
      objMessage.Subject = "Example CDO Message"
      objMessage.From = "[email protected]"
      objMessage.To = "[email protected]"
      objMessage.TextBody = "This is some sample message text."
      objMessage.Send
      the other elements you mention allow you to add different options

      like this:
      Code:
      'Not sure what this bit does.
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
       
      'Name or IP of Remote SMTP Server
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.myserver.com"
       
      'Server port (typically 25)
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
       
      objMessage.Configuration.Fields.Update

      sigpic


      Please do show your appreciation to those who assist you by leaving Rep Point

      Comment


      • #4
        Re: Email when a service falls over

        Cheers its working like a dream, These must be to do with the exchange server

        'Not sure what this bit does.
        objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

        'Name or IP of Remote SMTP Server
        objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.myserver.com"

        'Server port (typically 25)
        objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

        objMessage.Configuration.Fields.Update

        Comment


        • #5
          Re: Email when a service falls over

          yep.. two parts are to define the SMTP server and the Port.
          the other option it seems, it how it sends.

          (1) is send using pickup
          (2) is send using port
          (3) is send using exchange


          ref:
          http://msdn.microsoft.com/en-us/libr...chg.65%29.aspx

          sigpic


          Please do show your appreciation to those who assist you by leaving Rep Point

          Comment


          • #6
            Re: Email when a service falls over

            Silly Question

            I written a vb script to start the service, Silly question Can I give this to a user on their desktop to start the service? she only has domin user access.

            option explicit
            Dim cimv2, oService, Result , strComputer,strServiceName
            strComputer = "192.168.1.9" ' Local Computer
            strServiceName = "sage200" ' K3 Service
            'Get the WMI administration object
            Set cimv2 = GetObject("winmgmts:{impersonationLevel=impersonat e}!\\" & _
            strComputer & "\root\cimv2")
            'Get the service object
            Set oService = cimv2.Get("Win32_Service.Name='" & strServiceName & "'")


            'Path = "winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & _
            ' "\root\cimv2:Win32_Service.Name='" & strServiceName & "'"
            'Get the WMI administration object of the service
            'Set oService = GetObject(Path)
            'Check base properties
            If oService.Started Then
            ' the service is Not started
            wscript.echo "The service " & strServiceName & " is all ready running."
            Else
            ' Start the service
            oService.StartService
            wscript.echo "Start " & strServiceName & " is Now running:"
            End If

            Comment

            Working...
            X