If ObjError.Number <> 0 Then
strMessageToUse = "Error Number: " & ObjError.number & " Error Details: " & ObjError.Description
call ReturnResponse(true, strMessageToUse)
Else
strMessageToUse = "Script WMIFunctionalCheck executed Successfully"
call ReturnResponse(false, strMessageToUse)
End If
'---------------------------------------------------------------------------
' Retrieves the script output.
'---------------------------------------------------------------------------
Sub ReturnResponse(boolErrorFlag, strMessage)
If boolErrorFlag = true Then
oPropertyBag.AddValue "Status", "FAIL"
oPropertyBag.AddValue "ErrorMessage", strMessage
Else
oPropertyBag.AddValue "Status", "OK"
End If
oAPI.LogScriptEvent "WMIFunctionalCheck.vbs",100,EVENT_TYPE_INFORMATION, strMessage
Call oAPI.Return(oPropertyBag)
WScript.Quit
End Sub
'---------------------------------------------------------------------------
' Gets WMI Status.
'---------------------------------------------------------------------------
Function GetWMIStatus(strComputerName)
Dim Status
Status = ExecuteWMIQuery(strComputerName, "cimv2", "select Status from win32_operatingsystem", "Status")
If Status = "OK" Then
GetWMIStatus = "OK"
Else
GetWMIStatus = "FAIL"
End If
End Function
'---------------------------------------------------------------------------
' Retrieves a WMI object from the specified namespace.
'---------------------------------------------------------------------------
Function GetWMIObject(ByVal sNamespace)
dim oWMI
'get the object
on error resume next
set oWMI = GetObject(sNamespace)
ObjError.Save
on error goto 0
'did it work?
if IsEmpty(oWMI) then
'no
strMessageToUse = "Error Number: " & ObjError.number & " Unable to open WMI Namespace '" & sNamespace & "'. Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists."
call ReturnResponse(true, strMessageToUse)
end if
set GetWMIObject = oWMI
End Function
'---------------------------------------------------------------------------
' Execute a WMI Query.
'---------------------------------------------------------------------------
Function ExecuteWMIQuery(TargetComputer, strBaseClass, strQuery, strPropertyName)
Dim WbemSrv, WbemObjectSet, objItem
Set WbemSrv = GetWMIObject("winmgmts:{impersonationLevel=impersonate}!\\" & TargetComputer & "\root\" & strBaseClass)
Set WbemObjectSet = WbemSrv.ExecQuery(strQuery)
For Each objItem in WbemObjectSet
ExecuteWMIQuery = objItem.Properties_(strPropertyName).value
Next
End Function
'---------------------------------------------------------------------------
' Error Handling Class
'---------------------------------------------------------------------------
Class Error
Private m_lNumber
Private m_sSource
Private m_sDescription
Private m_sHelpContext
Private m_sHelpFile
Public Sub Save()
m_lNumber = Err.number
m_sSource = Err.Source
m_sDescription = Err.Description
m_sHelpContext = Err.HelpContext
m_sHelpFile = Err.helpfile
End Sub
Public Sub Raise()
Err.Raise m_lNumber, m_sSource, m_sDescription, m_sHelpFile, m_sHelpContext
End Sub
Public Sub Clear()
m_lNumber = 0
m_sSource = ""
m_sDescription = ""
m_sHelpContext = ""
m_sHelpFile = ""
End Sub
Public Default Property Get Number()
Number = m_lNumber
End Property
Public Property Get Source()
Source = m_sSource
End Property
Public Property Get Description()
Description = m_sDescription
End Property
Public Property Get HelpContext()
HelpContext = m_sHelpContext
End Property
Public Property Get HelpFile()
HelpFile = m_sHelpFile
End Property
End Class