在vb.net你怎么做阅读非隐藏的设备在设备管理器网络适配器面上看
问题描述:
我想读的网络适配器 as seen here 目前我使用的代码,我在网上找到在vb.net你怎么做阅读非隐藏的设备在设备管理器网络适配器面上看
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个设备的设备列表,还有一些隐藏的设备,看起来像是没有连接的设备。如何优化我的搜索以仅显示设备管理器默认显示的内容?
答
在另一个论坛上找到我的答案,但找不到链接。下面是答案:
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))