how to get hardware-id for a network adapter programmatically in C#
See the question and my original answer on StackOverflowThe HardwareID you're looking for is located in another WMI Class. Once you have an instance of a Win32_NetworkAdapeter, you can select a Win32_PnpEntry using the PNPDeviceId. Here is a sample code that list all network adapters and their hardware id, if any:
ManagementObjectSearcher adapterSearch = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_NetworkAdapter");
foreach (ManagementObject networkAdapter in adapterSearch.Get())
{
string pnpDeviceId = (string)networkAdapter["PNPDeviceID"];
Console.WriteLine("Description : {0}", networkAdapter["Description"]);
Console.WriteLine(" PNPDeviceID : {0}", pnpDeviceId);
if (string.IsNullOrEmpty(pnpDeviceId))
continue;
// make sure you escape the device string
string txt = "SELECT * FROM win32_PNPEntity where DeviceID='" + pnpDeviceId.Replace("\\", "\\\\") + "'";
ManagementObjectSearcher deviceSearch = new ManagementObjectSearcher("root\\CIMV2", txt);
foreach (ManagementObject device in deviceSearch.Get())
{
string[] hardwareIds = (string[])device["HardWareID"];
if ((hardwareIds != null) && (hardwareIds.Length > 0))
{
Console.WriteLine(" HardWareID: {0}", hardwareIds[0]);
}
}
}