在 vb.net 中,您如何读取设备管理器网络适配器部分中显示的非隐藏设备
In vb.net how do you read non-hidden devices as seen in device manager Network Adaptor section
我正在尝试读取网络适配器
as seen here
目前我正在使用我在网上找到的代码
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 个,还有一堆隐藏的设备和看起来像不再连接的设备。如何优化我的搜索以仅显示设备管理器默认显示的内容?
在另一个论坛上找到我的答案,但找不到 link。答案如下:
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))
我正在尝试读取网络适配器 as seen here 目前我正在使用我在网上找到的代码
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 个,还有一堆隐藏的设备和看起来像不再连接的设备。如何优化我的搜索以仅显示设备管理器默认显示的内容?
在另一个论坛上找到我的答案,但找不到 link。答案如下:
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))