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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI Connection hanging

Status
Not open for further replies.

josephk73

Technical User
Aug 1, 2002
115
GB
Hi guys I have a problem whereby I'm making a wmi query to around 500 servers. For the most part a connection is made without a problem. However I've got one or two servers that hang at the point of connecting to the WMI service on the machine.

I've tried error trapping (see below)and now I'm really stuck, as I reckon the script neither makes or is refused a connection hence the error trapping does not work.

I guess my question is if there is a way to say give a machine say 5 seconds to respond and if it doesn't assume a connection can't be made and the script goes onto the next machine.

Anycase, enough of my rambling, here is the code snippet I'm using..

Code:
strComputer="computerA"

Call getServices(strComputer)

Sub getServices (strComputer)
bolName=False
bolFlag=False
Err.Number=0
WScript.Echo strComputer
WScript.Echo "=============="
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
it is at this point the script is hanging and never gets to the next line to test the error number.
    If Err.Number<>0 Then
     WScript.Echo "Machine could not be contacted. Please check manually"
     Else
     Wscript.Echo "Machine contacted"
    End If
    
End Sub
 
I was helping someone out yesterday at work with a script where we ran into something similar with a workstation. Since the problem was when it was connecting there was no way to catch the error or add any code to wait for a period of time. In the end it turned out that WMI was corrupted on that workstation and repairing it did the trick.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Thanks dm4ever.

You might have something there. A real problem then. Imagine running a script overnight against 1000 machines and it gets stuck halfway. You come back in the morning with only half your results. Explain that to your manager :-(

If it is a corruption how do you go about fixing it. Is there a knowledge base article or do you have an outline for the procedure?

thx
 
I'd recommend that you check WMI on those servers/workstations by executing WBEMTEST and MS WMIDiag.vbs.

If there does appear to be an issue with WMI the following has worked for me.

1. stop the WMI service: net stop winmgmt
2. then rename the current Repository folder "C:\WINDOWS\system32\wbem\Repository" and then do run the following commands
3. run the following commands:
for %i in (*.dll) do RegSvr32 -s %i
for %i in (*.exe) do %i /RegServer
for %i in (*.mof, *.mfl) do Mofcomp %i

NOTE: MS does not recommend this as the first step in attempting to repair WMI, but it is the one method that has worked for me on over 50 workstations. Things to keep in mind is that MOF files that third party apps install may not get rebuilt if autorecover is not set for them.

In extreme cases I've had to copy content of the entire WBEM folder from a similar configured (hardware/software) workstation to the one experiencing the problems and followed the same steps above.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
dm4ever

Thanks for your advice and time.

Cheers,

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top