我得到一個帶有GetBestInterface(iphlpapi.dll)的InterfaceIndex。c#NetworkInterface.GetAllNetworkInterfaces vs WMI Win32_NetworkAdapter
目標:讀取其他接口屬性。
此WMI查詢速度慢:
SELECT MACAddress,Name,GUID,NetConnectionID FROM Win32_NetworkAdapter WHERE InterfaceIndex=
在C#中有,速度更快,
NetworkInterface.GetAllNetworkInterfaces()
但每個NetworkInterface的卻沒有財產InterfaceIndex(原文如此!)。
我不知道如何優化這樣的:似乎
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 \系統\ CurrentControlSet \服務\ TCPIP \參數\接口
HKLM \系統\ CurrentControlSet \控制\網絡{4D36E972-E325-11CE-BFC1-08002BE10318}
我發現並給予好評的[解決方案] [1] [1]:http://stackoverflow.com/a/11059702/471232 – Massimo
所以我的最後一個問題是,在一般:如何緩存和速度 - up wmi查詢? – Massimo