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


Try using

Set objWMIService = Nothing

before looping back to the next ip address.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy