Retrieving Networking Configuration Information Using Visual Basic.NET and VBScript - How to retrieve Network Client Information using Visual Basic.NET
(Page 5 of 6 )
Before getting the information on “Network Clients” installed on your computer, we need to create a wrapper to store the same information. Let us proceed with creating a wrapper:
Public Function getNetworkClientStructure() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("Caption"))
dt.Columns.Add(New DataColumn("Description"))
dt.Columns.Add(New DataColumn("InstallDate"))
dt.Columns.Add(New DataColumn("Manufacturer"))
dt.Columns.Add(New DataColumn("Name"))
Return dt
End Function
The following method “addNetworkClient” adds a single row based on the structure you create for the data table using the above method.
Public Sub addNetworkClient(ByRef dt As DataTable, ByVal Caption As String, ByVal Description As String, ByVal InstallDate As String, ByVal Manufacturer As String, ByVal Name As String)
Dim dr As DataRow
dr = dt.NewRow
dr("Caption") = Caption
dr("Description") = Description
dr("InstallDate") = InstallDate
dr("Manufacturer") = Manufacturer
dr("Name") = Name
dt.Rows.Add(dr)
End Sub
Once you complete the creation of wrapper, the following VB.NET code should support it with some minimum information of “NetworkClients” 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_NetworkClient")
Dim dt As DataTable = globals.getNetworkClientStructure
For Each queryObj As ManagementObject In searcher.Get()
globals.addNetworkClient(dt, queryObj("Caption"), queryObj("Description"), queryObj("InstallDate"), queryObj("Manufacturer"), queryObj("Name"))
Next
Me.DataGrid1.DataSource = dt
Catch err As Exception
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
End Sub
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_NetworkClient",,48)
For Each objItem in colItems
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "InstallDate: " & objItem.InstallDate
Wscript.Echo "Manufacturer: " & objItem.Manufacturer
Wscript.Echo "Name: " & objItem.Name
Next
Next: How to retrieve Win Proxy Information using Visual Basic.NET >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee