Hi All,
Been a long time since my last thread but here we go.
I'm using VS.NET 2010 Prof Beta at the moment and I'm trying to list all Nic Cards and their settings into a text box. I succeeded with a script from the web (which had an error in the first place) and some adjustments to it.
But.....
It lists all hidden devices too (as to be shown in Device manager: Show hidden devices) I worked my way around it and let it jump to next if it doesn't have a IP address, but I find this a bit clumsy and want to really skip them if they are hidden and not just the way I did this now. Plus it still does show the same NiC (different name, same MAC#) in the list because it has an IP, but in Device manager this one is hidden.
Anyone can give me a hint on how to do this?
here is my code:
Thanks in advance
Been a long time since my last thread but here we go.
I'm using VS.NET 2010 Prof Beta at the moment and I'm trying to list all Nic Cards and their settings into a text box. I succeeded with a script from the web (which had an error in the first place) and some adjustments to it.
But.....
It lists all hidden devices too (as to be shown in Device manager: Show hidden devices) I worked my way around it and let it jump to next if it doesn't have a IP address, but I find this a bit clumsy and want to really skip them if they are hidden and not just the way I did this now. Plus it still does show the same NiC (different name, same MAC#) in the list because it has an IP, but in Device manager this one is hidden.
Anyone can give me a hint on how to do this?
here is my code:
VB.NET:
Imports System.Management
Public Class Form1
Public Function getNetworkAdapterStructure() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("AdapterType"))
dt.Columns.Add(New DataColumn("MACAddress"))
dt.Columns.Add(New DataColumn("Manufacturer"))
Return dt
End Function
Public Sub addNetworkAdapterRow(ByRef dt As DataTable, ByVal AdapterType As String, ByVal MACAddress As String, ByVal Manufacturer As String)
Dim dr As DataRow
dr = dt.NewRow
dr("AdapterType") = AdapterType
dr("MACAddress") = MACAddress
dr("Manufacturer") = Manufacturer
dt.Rows.Add(dr)
End Sub
Private Sub btnExtended_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExtended.Click
TextBox1.Text = ""
Try
Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_NetworkAdapterConfiguration")
For Each queryObj As ManagementObject In searcher.Get()
If queryObj("IPAddress") Is Nothing Then GoTo NotNeeded
Me.TextBox1.Text &= "Caption: " + queryObj("Caption") & ControlChars.NewLine
Me.TextBox1.Text &= "DHCPEnabled: " + (queryObj("DHCPEnabled").ToString) & ControlChars.NewLine
Me.TextBox1.Text &= "DHCPServer: " + queryObj("DHCPServer") & ControlChars.NewLine
Me.TextBox1.Text &= "DNSDomain: " + queryObj("DNSDomain") & ControlChars.NewLine
Me.TextBox1.Text &= "DNSHostName: " + queryObj("DNSHostName") & ControlChars.NewLine
If queryObj("IPAddress") Is Nothing Then
Me.TextBox1.Text &= "IPAddress: " + queryObj("IPAddress") & ControlChars.NewLine
Else
Dim arrIPAddress As String()
arrIPAddress = queryObj("IPAddress")
For Each arrValue As String In arrIPAddress
Me.TextBox1.Text &= "IPAddress: {0}" + arrValue & ControlChars.NewLine
Next
End If
If queryObj("IPSubnet") Is Nothing Then
Me.TextBox1.Text &= "IPSubnet: " + queryObj("IPSubnet") & ControlChars.NewLine
Else
Dim arrIPSubnet As String()
arrIPSubnet = queryObj("IPSubnet")
For Each arrValue As String In arrIPSubnet
Me.TextBox1.Text &= "IPSubnet: {0}" + arrValue & ControlChars.NewLine
Next
End If
Me.TextBox1.Text &= "MACAddress: {0}" + queryObj("MACAddress") & ControlChars.NewLine
Me.TextBox1.Text &= "======================================" & ControlChars.NewLine
NotNeeded: Next
Catch err As ManagementException
MessageBox.Show("An error occurred while querying forWMI data: " & err.Message)
End Try
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
End
End Sub
End Class
Thanks in advance