Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

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
Else
	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
    Else
         ' Insert code here 
    End If
Next

The ping test below is good too.

share|improve this answer

Your Answer

 
discard

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