Sign in to follow this  
Followers 0
gcue

objget exit if error

3 posts in this topic

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

Share this post


Link to post
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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

actually i figured it out.. it was coming from an array call later..

so i did a if not isarray check which worked!

thanks anyway!!

Edited by gcue

Share this post


Link to post
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
Sign in to follow this  
Followers 0