Sign in to follow this  
Followers 0
jaswicki

Errormode

4 posts in this topic

I am writing some code to do a WMI call and on machines with corrupted WMI it is erroring out. Is there a way to supress all errors like the errormode(@OFF) command in Winbatch so that I can capture and do my own error handling? The second line below is the one throwing the error. It works fine on a machine without WMI issues.

$objWMI = ObjGet("winmgmts:\\localhost\root\CIMV2")
$objItems = $objWMI.ExecQuery("SELECT * FROM Win32_SystemEnclosure", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

Share this post


Link to post
Share on other sites



Since this is an Object you can use ObjEvent("AutoIt.Error", ... to catch the error.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try some error checking.

$objWMI = ObjGet("winmgmts:\\localhost\root\CIMV2")
If IsObj($objWMI) Then
    $objItems = $objWMI.ExecQuery("SELECT * FROM Win32_SystemEnclosure", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
Else
    MsgBox(0, "Error", Unable to get the object")
EndIf

Also look in the Help file under Obj/Com reference, about 2/3 of the way down the page there is a good example of error handling.

EDIT: Another common problem with WMI is that the service is disabled. You should check for that as well and if it's disabled then enable it.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Try some error checking.

$objWMI = ObjGet("winmgmts:\\localhost\root\CIMV2")
If IsObj($objWMI) Then
    $objItems = $objWMI.ExecQuery("SELECT * FROM Win32_SystemEnclosure", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
Else
    MsgBox(0, "Error", Unable to get the object")
EndIf

Also look in the Help file under Obj/Com reference, about 2/3 of the way down the page there is a good example of error handling.

EDIT: Another common problem with WMI is that the service is disabled. You should check for that as well and if it's disabled then enable it.

Thanks for the quick relpies!

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