Link to home
Start Free TrialLog in
Avatar of johnnyg123
johnnyg123Flag for United States of America

asked on

vbs script to check MSSQLSERVER

I have the following script running as a scheduled task (has been running for over a year)

(note: computer/email names changed for security)

Set objComputer = GetObject("WinNT://test123,computer")
objComputer.Filter = Array("Service")
            Dim iMsg
            Dim iConf
            Dim Flds
            Dim strHTML
            Dim strSmartHost

            Const cdoSendUsingPort = 2
            StrSmartHost = "mail.test.local"

            set iMsg = CreateObject("CDO.Message")
            set iConf = CreateObject("CDO.Configuration")

            Set Flds = iConf.Fields


            With Flds
                  .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
                  .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSmartHost
                  .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
                  .Update
            End With
For Each aService In objComputer
      select case aService.Name
            case "MSSQLSERVER"
                  if aService.Status <> 4 then
      
                        With iMsg
                              Set .Configuration = iConf
                              .To = "IT@elgin.com"
                              .From = "Webdbadmin@elgin.com"
                              .Subject = "The SQL Server on test123 is not running!"
                              .TextBody = "SQL Server is not running. ."
                              .Send
                        End With
            
                  end if

                  end select
      
Next

      Set iMsg = Nothing
      Set iConf = Nothing
      Set Flds = Nothing


We started receiving the message saying it is not running when it is

Any one have ideas as to why the false negative?
Avatar of lcohan
lcohan
Flag of Canada image

I suggest you add more areas to the Topic (and tags) as this is not (purely) a MS SQL Server question in my opinion.
ASKER CERTIFIED SOLUTION
Avatar of Seaton007
Seaton007
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial