Jump to content

Trapping object errors


Recommended Posts

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

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...