Get DEVPKEY_Device_BusReportedDeviceDesc from Win32_PnPEntity in c#
See the question and my original answer on StackOverflowThe GetDeviceProperties method is documented like this:
Uint32 GetDeviceProperties(
[in, optional] string devicePropertyKeys[],
[out] Win32_PnPDeviceProperty deviceProperties[]
);
So here is a sample code to call it with C#:
foreach (var mo in new ManagementObjectSearcher(null, "SELECT * FROM Win32_PnPEntity").Get().OfType<ManagementObject>())
{
// get the name so we can do some tests on the name in this case
var name = mo["Name"] as string;
// add your custom test here
if (name == null || name.IndexOf("(co", StringComparison.OrdinalIgnoreCase) < 0)
continue;
// call Win32_PnPEntity's 'GetDeviceProperties' method
// prepare two arguments:
// 1st one is an array of string (or null)
// 2nd one will be filled on return (it's an array of ManagementBaseObject)
var args = new object[] { new string[] { "DEVPKEY_Device_BusReportedDeviceDesc" }, null };
mo.InvokeMethod("GetDeviceProperties", args);
// one mbo for each device property key
var mbos = (ManagementBaseObject[])args[1];
if (mbos.Length > 0)
{
// get value of property named "Data"
// not all objects have that so we enum all props here
var data = mbos[0].Properties.OfType<PropertyData>().FirstOrDefault(p => p.Name == "Data");
if (data != null)
{
Console.WriteLine(data.Value);
}
}
}