我在c#方面非常新手,但不幸的是,我不得不发现usb端口、VIDs和PID。
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
}
}
}实际上,我不明白这个密钥"Caption"是从哪里来的。我如何知道隐藏在这个对象中的还有哪些键?对我来说还不清楚。怎样才能得到其他"Keys"的列表?
发布于 2017-05-06 12:03:18
此代码由WMI访问不同的属性。具体来说,Win32_PnPEntity类表示即插即用设备的属性。
请参阅有关PnPEntity类及其属性的MSDN的更多信息:
[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... */
};https://stackoverflow.com/questions/43820189
复制相似问题