I get a InterfaceIndex with GetBestInterface (iphlpapi.dll).
The goal : read other interface properties.
This WMI query is slow :
SELECT MACAddress,Name,GUID,NetConnectionID FROM Win32_NetworkAdapter WHERE InterfaceIndex=
In C# there is, faster,
NetworkInterface.GetAllNetworkInterfaces()
but each NetworkInterface hasn't the property InterfaceIndex ( sic ! ).
I don't know how to optimize this :
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)
The options don't seem to help. Can I split the operations and cache any step ?
Or another path : avoid WMI and lookup the interface ( with InterfaceIndex ) from the registry ?
HKLM\SYSTEM\CurrentControlSet\Services\tcpip\Parameters\Interfaces
HKLM\SYSTEM\CurrentControlSet\Control\Network{4D36E972-E325-11CE-BFC1-08002BE10318}