Jump to content

objget exit if error


gcue
 Share

Recommended Posts

i have the following script that checks for an event log but i want it to error out if it doesnt find the log.. ive tried isnotarray($objWMIService) and "if @error" at different spots but i still get "subscript used with non-Array variable"

$Query_Clause = "Select * FROM Win32_NTLogEvent WHERE Logfile = 'Application' AND Type = 'Information' AND SourceName = 'Altiris Recovery Solution' AND EventCode = 31"
    $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate,(Security)}!\\" & $asset & "\root\cimv2")
    
;~  If Not IsArray($objWMIService) Then
;~      Local $aText[3] = ["Dashboard", @TAB & "Status", @TAB & @TAB & "Idle"]
;~      Local $aParts[3] = [200, 175, -1]
;~      $dSTATUS = _GUICtrlStatusBar_Create($dGUI, $aParts, $aText)
;~      MsgBox(0, "Check Recovery Solution", "No successful snapshots have been taken.")
;~      Return
;~  EndIf
    
    If IsObj($objWMIService) Then
        $colItems = $objWMIService.ExecQuery($Query_Clause)
        If IsObj($colItems) Then
            For $objEvent In $colItems
                $Output = ""
                $Output &= "Message: " & $objEvent.Message & @CRLF
                $message = $Output
                ExitLoop
            Next
        EndIf
    EndIf
Link to comment
Share on other sites

@gcue

Maybe...

Func _ObjGet()
    $Query_Clause = "Select * FROM Win32_NTLogEvent WHERE Logfile = 'Application' AND Type = 'Information' AND SourceName = 'Altiris Recovery Solution' AND EventCode = 31"
    $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate,(Security)}!\\" & $asset & "\root\cimv2")
    If $objWMIService = 0 Then
        SetError(1)
        Return 0
    ElseIf $objWMIService <> '' Then
        Return 1
    EndIf
    SetError(2)
    Return 0
EndFunc   ;==>_ObjGet

If _ObjGet() Then
    MsgBox(64, "ObjGet", $objWMIService)
Else
    MsgBox(16, "ObjGet", "Error : " & @error)
EndIf

Cheers, FireFox.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...