Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an issue when connecting to remote machines using the following:

Set objWMIService = objSWbemLocator.ConnectServer _ (sIP, "root\CIMV2", strUser, strPassword, "MS_409", "ntlmdomain:" + sDomain, 128)

the problem is that some machines are not timing out and the process hangs.

Is there a way to cancel the connect and continue with the next ip? I'm using vbscript.

Thanks, Sam

share|improve this question

Try using

Set objWMIService = Nothing

before looping back to the next ip address.

share|improve this answer
No, it works fine for many machines on a list, but on specific ones it hangs. – Sam Jul 21 '09 at 18:12
Since you already have the wbemConnectFlagUseMaxWait flag set, it would appear that some of your servers don't recognize it. There is no close method for the SWbemLocator object, that was why I suggested setting the object to Nothing before attempting the next connection. – KevinH Jul 21 '09 at 18:55

is it because those machines are not available on network ? can you run a ping test before connecting to it through WMI.

Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
	Ping = True
	Ping = False
End If
End Function
share|improve this answer
On Error Resume Next
For each IP in IP_List
    Set objWMIService = objSWbemLocator.ConnectServer _ (sIP, "root\CIMV2", strUser, strPassword, "MS_409", "ntlmdomain:" + sDomain, 128)
    If Err.Number <> 0 Then 
        wscript.echo "Could not bind to WMI on " + sIP
         ' Insert code here 
    End If

The ping test below is good too.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.