Victor.Wiedemann Victor.Wiedemann - 1 year ago 75 Question

In how do you read non-hidden devices as seen in device manager Network Adaptor section

I am trying to read the network adapters
as seen here
at the moment I am using the code I found online

Sub Main()
Dim path As ManagementPath = New ManagementPath()
path.Server = "."
path.NamespacePath = "root\CIMV2"
Dim scope As ManagementScope = New ManagementScope(path)
Dim query As ObjectQuery = New ObjectQuery("SELECT * FROM Win32_NetworkAdapter")
Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher(scope, query)
Dim queryCollection As ManagementObjectCollection = searcher.Get()
Dim m As ManagementObject
For Each m In queryCollection
Console.WriteLine("Device Name : {0}", m("Name"))
End Sub

Right now I am seeing a list of devices that include those 4, but also a bunch of hidden devices and what looks like devices that are not connected anymore. How do I refine my search to only show what the device manager shows by default?

Answer Source

Found my answer on another forum, but cannot find the link again. Here is the answer:

  Dim moIP As ManagementObject
    Dim myNet = New ManagementObjectSearcher _
    ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") 
    Dim CountIncrement As Int16 = 1
    For Each moIP In myNet.Get
        'find device with  MAC Address
        If CStr(moIP("MACAddress")) = "00:11:22:33:44:55" Then
          'code here
        End If
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download