I'm working on a WMI script that polls all network adapters on a computer. If 2 conditions are true (IP is enabled and NIC is connected) then get the IP Address, Subnet Mask, and Default Gateway from the NIC. (These fields are arrays. I acquire them by using the Join function.)
Well... In the case of a system with multiple NICs that are active (Like a system running VMWare) I get this error when the script tries to enumerate the DefaultIPGateway:
(11, 5) Microsoft VBScript runtime error: Invalid use of Null: 'Join'
I tried putting an IF statement around the Join, but that errors also.
What I want to happen is: if that field is null, then exit this iteration of the for loop.
PSC
Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
Well... In the case of a system with multiple NICs that are active (Like a system running VMWare) I get this error when the script tries to enumerate the DefaultIPGateway:
(11, 5) Microsoft VBScript runtime error: Invalid use of Null: 'Join'
I tried putting an IF statement around the Join, but that errors also.
What I want to happen is: if that field is null, then exit this iteration of the for loop.
Code:
Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
Set objNICInfo = objWMI.ExecQuery("Select * from Win32_NetworkAdapter Where NetConnectionStatus = 2")
For Each strActiveAdapter In objNICInfo
Set objIPInfo = objWMI.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where Index = " & strActiveAdapter.Index)
For Each strIPInfo In objIPInfo
If strIPInfo.IPEnabled = True Then
strAddress = Join(strIPInfo.IPAddress, ",")
[red] ' If strIPInfo.DefaultIPGateway <> Null Then
strGateway = Join(strIPInfo.DefaultIPGateway, ",")
' End If[/red]
strMask = Join(strIPInfo.IPSubnet, ",")
WScript.Echo "Adapter: " & strActiveAdapter.Name
WScript.Echo "Address: " & strAddress
WScript.Echo "Mask: " & strMask
WScript.Echo "Gateway: " & strGateway
End If
Next
Next
PSC
Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers