Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to determine if array is Null 1

Status
Not open for further replies.

PScottC

MIS
Mar 16, 2003
1,285
US
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.

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
 
One more thing... Here's the network configuration on the box running vmware.

NIC1 (production)
IP: 172.16.2.10
SM: 255.255.255.0
GW: 172.16.2.1

NIC2 (VMWare VMNet1)
IP: 192.168.12.1
SM: 255.255.255.0
GW:

NIC3 (VMWare VMNet8)
IP: 192.168.34.1
SM: 255.255.255.0
GW:

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
 
[tt]>If strIPInfo.DefaultIPGateway <> Null Then
If not isNull(strIPInfo.DefaultIPGateway) Then[/tt]
 
Thanks for your help! Have a star.

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top