Sign in to follow this  
Followers 0
JonnyThunder

Trapping object errors

2 posts in this topic

Hello,

I've got a script that runs through a list of PCs and uses WMI to connect to the PC, and extract some information about memory / modem / manufacturer. The problem is, the script will hang if there is an issue with WMI. it sits for quite some time before giving this error: "The requested action with this object has failed". Are there any error trapping fascilities for using WMI objects? Also, what is the cleanest way to destroy the WMI object after use?

I'm using this code to initiate the WMI object:

; Create WMI object
$objWMIService = ObjGet("winmgmts:\\" & $machine & "\root\CIMV2")
; Check WMI is active
if isobj($objWMIService) Then
    ; Do stuff here
else
    ; couldnt connect to WMI
Endif
; Clear WMI object?
$objWMIService = ""

There must be a machine out in our network which has WMI problems - but how can I ensure my script doesn't die when it gets to these machines? The script above catches most of the instances where it cant get a WMI connection, but I think the machines that make the script die, there IS a WMI connection - but the query hangs it.

Thanks,

Simon

Share this post


Link to post
Share on other sites



You can always use IE.au3's error handler. Just include the following toward the top of your script.

_IEErrorHandlerRegister()

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