1

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

3 Answers 3

1

Try using

Set objWMIService = Nothing

before looping back to the next ip address.

2
  • No, it works fine for many machines on a list, but on specific ones it hangs.
    – Sam
    Jul 21, 2009 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, 2009 at 18:55
1

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
Else
    Ping = False
End If
End Function
0
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
    Else
         ' Insert code here 
    End If
Next

The ping test below is good too.

You must log in to answer this question.