Reputation: 67476
I am quite novice in c# but unfortunately have to discover usb ports VIDs and PIDs.
ObjectQuery objectQuery = new ObjectQuery("SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0");
ManagementObjectSearcher comPortSearcher = new ManagementObjectSearcher(connectionScope, objectQuery);
using (comPortSearcher)
{
string caption = null;
foreach (ManagementObject obj in comPortSearcher.Get())
{
if (obj != null)
{
object captionObj = obj["Caption"];
// Rest of code
}
}
}
I actually can't understand whre this key "Caption"
comes from. How can I know what else keys are hidden in this object? It is very unclear for me.
How can I get the list of other of such a "Keys"
Upvotes: 1
Views: 1316
Reputation: 37299
This code accesses by WMI different properties. Specifically Win32_PnPEntity
class represents the properties of a Plug and Play device.
See more on MSDN about Win32_PnPEntity class and it's properties:
[Dynamic, Provider("CIMWin32"), UUID("{FE28FD98-C875-11d2-B352-00104BC97924}"), AMENDMENT]
class Win32_PnPEntity : CIM_LogicalDevice
{
uint16 Availability;
string Caption;
string ClassGuid;
string CompatibleID[];
uint32 ConfigManagerErrorCode;
/* Rest of properties... */
};
The ManagementObjectSearcher
is one way to retrieve information of a WMI Class
Upvotes: 1