【发布时间】:2013-08-19 19:32:34
【问题描述】:
我通过 GetBestInterface (iphlpapi.dll) 获得一个 InterfaceIndex。
目标:读取其他接口属性。
这个 WMI 查询很慢:
SELECT MACAddress,Name,GUID,NetConnectionID FROM Win32_NetworkAdapter WHERE InterfaceIndex=
在 C# 中,速度更快,
NetworkInterface.GetAllNetworkInterfaces()
但每个 NetworkInterface 都没有属性 InterfaceIndex (sic !)。
我不知道如何优化这个:
EnumerationOptions wmi_options = new EnumerationOptions();
wmi_options.Rewindable = false;
wmi_options.ReturnImmediately = true;
string wql = "SELECT MACAddress,Name,GUID,NetConnectionID FROM Win32_NetworkAdapter WHERE InterfaceIndex=" + iface;
ManagementObjectCollection recordset = new ManagementObjectSearcher(@"root\cimv2", wql, wmi_options).Get();
foreach (ManagementObject mo in recordset)
这些选项似乎没有帮助。 我可以拆分操作并缓存任何步骤吗?
或其他路径:避免 WMI 并从注册表中查找接口(使用 InterfaceIndex )?
HKLM\SYSTEM\CurrentControlSet\Services\tcpip\Parameters\Interfaces
HKLM\SYSTEM\CurrentControlSet\Control\Network{4D36E972-E325-11CE-BFC1-08002BE10318}
【问题讨论】:
-
我找到并赞成[解决方案][1] [1]:stackoverflow.com/a/11059702/471232
-
所以我的最后一个问题是,一般来说:如何缓存和加速 wmi 查询?