Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WSH VBscript hangs on WMI call

Status
Not open for further replies.

skoehler

MIS
Mar 7, 2001
6
US
Been searching through this and other forums, to no avail.

Most desktop machines in my environment are running W2K, WXP, and a few NT's. I keep running into an issue with performing a WMI query, where it appears the script hangs (current test been hanging on line for 70 mins). I assume This is because of older versions of or problematic WMI instances. I was looking for a simple way to verify WMI capability without being dependent on WMI itself? Only workaround I can think of is to use something like reg.exe to see if I pull WMI version from somewhere in registry, however a method that wouldn't require a dependency on another util would be preferred.
 
WshShell.RegRead, will get you reg info.
where is your WMI query?
 
Bringing this back to the surface with some detail....

Used to have a ton of issues making remote WMI calls and it freezing my script. I wasn't even able to trap an error to make a decision from - it just froze.

I've since found the following line w/ an error trap as a good method to verify my WMI "connectibility", where I won't even attempt a WMI call against that machine if this comes back with anything other than a 0:

Set objWMIService = objWbemLocator.ConnectServer(strMachine,root,,,,, wbemConnectFlagUseMaxWait)

So now on to my issue - I have a script I'm running against 10k or so machines remotely, and found 1 problematic machine so far where my script still freezes. My goal is to find any way to trap an error, or do some further prerequisite check before hand that can ID the machine as a potential issue so I can allow script to continue.

Here's the snipet of code, however if someone wants to see entire script (1100+ lines) let me know and more than happy to post:

On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strMachine & "\root\cimv2")
strTempVar1 = Err.Number '-----> For machine in question, this is 0
On Error Goto 0
If strTempVar1 = 0 Then
On Error Resume Next
Set colDomains = objWMIService.ExecQuery ("Select Domain from Win32_ComputerSystem") '-----> For machine in question, this is 0
On Error Goto 0
If VarType(colDomains) = 9 Then '-----> For machine in question, this is 9
For Each strDomain In colDomains '-----> This is where the script just hangs
objResultDict.Item("Machine_Domain") = strDomain.Domain
Next



I should also add that during debug, colDomains.count also freezes.

Any thoughts?



 
You may try this:
Set colDomains = objWMIService.ExecQuery ("Select Domain from Win32_ComputerSystem"[!], "WQL", 48[/!])

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That didn't get me by the freeze on the "For Each" line, however it was able to get me to the point where evaluating colDomains.count didn't freeze, and I'm fortunate in that when this problem occurs, that ends up being an empty value.

Therefore I can evaluate the count, and skip the For Each logic if it's empty....so that'll work perfect!!!!

So thank you a ton for the quick response!

One last question - can you briefly explain what those additional params are for? Was having difficulty searching for references......
 
[1] You can ping the strMachine to see if it's alive.
[2] The for-each won't probably not the source of hanging, it is most probably the getobject binding to the remote m/c. There is a default timeout which takes minutes.
 
Thanks for the responses guys - however PH's solution didn't work upon further investigation.

As stated above, while "For Each" line was still freezing, I was able to evaluate the colDomains.count w/o freezing.......but on further investigation, the colDomains.count property always ends up empty (where it is populated with a "1" when removing the ,"WQL",48 line from the end of ExecQuery line).

Tsuji - I actually have several checks occuring before this point in the logic - just didn't post entire script due to length. When I reach this chunk of code, I've already successfully checked:
- Successful ping response
- DNS record verification (we have some cases w/ dupe records where diff machine responds to ping, leading to believe the machine is live)
- Successfully connect to \\machine\c$ share.

So at this point, the machine is live.

Given all that, I'm back to square one - just looking for any way to proceed past this logic that's completely freezing on me. Without obviously knowing the solution, I'm thinking I should be able to do something like:
- Change around WMI query w/ other params
- Set some sort of timeout
- Some alternative way to evaluate a property or something for colDomains that I can use to determine there's some issue. Remember however that even a colDomains.count (where I could evaluate for empty) will freeze.
- Send someone to accidentily drop this PC off the desk, since it's the only one out of 10k that's giving me a prob ;-)


As always, any help is appreciated......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top