I'm trying to get the bus reported device description from a usb com port in our WPF application. Found a powershell script that gives exacly that, but as not every user has permission to run powershell, so using PowerShell.Create() is sadly not an option.
(Get-WMIObject Win32_PnPEntity | where {$_.name -match "\(com*"}).GetDeviceProperties("DEVPKEY_Device_BusReportedDeviceDesc").DeviceProperties.Data
I have tried below combinations, but I either get "Unable to cast object of type 'System.String' to type 'System.Array'" or "Invalid method Parameter(s)" on InvokeMethod.
using System;
using System.Management;
ManagementClass oClass = new ManagementClass("Win32_PnPEntity");
Object[] single = { "DEVPKEY_Device_BusReportedDeviceDesc" };
Array arr = (Array)new string[] { "DEVPKEY_Device_BusReportedDeviceDesc" };
Object[] singleArr = { single };
Object[] objsArr = { arr };
ManagementBaseObject inParams = oClass.GetMethodParameters("GetDeviceProperties");
inParams["devicePropertyKeys"] = single;
//inParams["devicePropertyKeys"] = arr;
//inParams["devicePropertyKeys"] = singleArr;
//inParams["devicePropertyKeys"] = objsArr;
oClass.InvokeMethod("GetDeviceProperties", single);
//oClass.InvokeMethod("GetDeviceProperties", singleArr);
//oClass.InvokeMethod("GetDeviceProperties", objsArr);
//oClass.InvokeMethod("GetDeviceProperties", inParams, null);
Everything takes place on the local machine.
Also found an answer from vromanov How to get Bus Reported Device Description using C# and it works, but seems like an overkill solution