0

我正在尝试阅读 此处看到的网络适配器, 此时我正在使用我在网上找到的代码

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"))
    Next
    Console.ReadLine()
End Sub

现在我看到了一个包含这 4 个设备的列表,还有一堆隐藏的设备以及看起来像不再连接的设备。如何优化搜索以仅显示设备管理器默认显示的内容?

4

1 回答 1

0

在另一个论坛上找到我的答案,但无法再次找到链接。这是答案:

  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            
        Console.WriteLine()
        'find device with  MAC Address
        If CStr(moIP("MACAddress")) = "00:11:22:33:44:55" Then
          'code here
        End If
    Next

编辑:在 for 循环中,也可以进行这些检查以查找有关连接设备的信息。

        Console.WriteLine("Device Name : {0}", moIP("Caption"))
        Console.WriteLine("Service Name : {0}", moIP("ServiceName"))
        Console.WriteLine("Description Name : {0}", moIP("Description"))
        Console.WriteLine("MAC : {0}", moIP("MACAddress"))
        Console.WriteLine(moIP("IPAddress")(0))
于 2016-06-06T19:06:01.717 回答