Retrieving Networking Configuration Information Using Visual Basic.NET and VBScript - How to retrieve MAC address and other miscellaneous network information using Visual Basic.NET – the code
(Page 4 of 6 )
Once you complete the creation of the wrapper (as specified in the previous section), proceed with the following VB.NET code to list all the in-depth details of network configuration information available on your system.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
Dim dt As DataTable = globals.getNetworkConfigStructure
For Each queryObj As ManagementObject In searcher.Get()
Dim IPXNetworkNumber As String = ""
If queryObj("IPXNetworkNumber") Is Nothing Then
IPXNetworkNumber = queryObj("IPXNetworkNumber")
Else
Dim arrIPXNetworkNumber As String()
arrIPXNetworkNumber = queryObj("IPXNetworkNumber")
For Each arrValue As String In arrIPXNetworkNumber
IPXNetworkNumber &= arrValue
Next
End If
globals.addNetworkConfig(dt, queryObj("Caption"), queryObj("IPFilterSecurityEnabled"), queryObj("IPPortSecurityEnabled"), queryObj("IPXAddress"), queryObj("IPXEnabled"), IPXNetworkNumber, queryObj("MACAddress"), queryObj("WINSPrimaryServer"), queryObj("WINSSecondaryServer"))
Next
Me.DataGrid1.DataSource = dt
Catch err As Exception
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
You can achieve the same thing with VBScript as follows:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True",,48)
For Each objItem in colItems
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "IPFilterSecurityEnabled: " & objItem.IPFilterSecurityEnabled
Wscript.Echo "IPPortSecurityEnabled: " & objItem.IPPortSecurityEnabled
Wscript.Echo "IPXAddress: " & objItem.IPXAddress
Wscript.Echo "IPXEnabled: " & objItem.IPXEnabled
If isNull(objItem.IPXNetworkNumber) Then
Wscript.Echo "IPXNetworkNumber: "
Else
Wscript.Echo "IPXNetworkNumber: " & Join(objItem.IPXNetworkNumber, ",")
End If
Wscript.Echo "MACAddress: " & objItem.MACAddress
Wscript.Echo "WINSPrimaryServer: " & objItem.WINSPrimaryServer
Wscript.Echo "WINSSecondaryServer: " & objItem.WINSSecondaryServer
Next
Next: How to retrieve Network Client Information using Visual Basic.NET >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee