解析 WMI 中 Win32_PnPEtities 的层次结构
我正在使用 WMI 查询来接收插入或拔出 USB 设备时的事件。
SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_USBControllerDevice'
从收到的事件中,我使用 Dependent
对象来获取 Win32_PnPEntity。
问题是,对于几乎任何物理设备,都至少有两个逻辑设备。 所以我收到的数据如下:
Device unplugged: LPK25
Device unplugged: USB Composite Device
Device plugged: LPK25
instance of Win32_PnPEntity
{
Caption = "LPK25";
ClassGuid = "{4d36e96c-e325-11ce-bfc1-08002be10318}";
CompatibleID = {"USB\\Class_01&SubClass_01&Prot_00", "USB\\Class_01&SubClass_01", "USB\\Class_01"};
ConfigManagerErrorCode = 0;
ConfigManagerUserConfig = FALSE;
CreationClassName = "Win32_PnPEntity";
Description = "USB Audio Device";
DeviceID = "USB\\VID_09E8&PID_0076&MI_00\\6&383464A1&0&0000";
HardwareID = {"USB\\VID_09E8&PID_0076&REV_0100&MI_00", "USB\\VID_09E8&PID_0076&MI_00"};
Manufacturer = "(Generic USB Audio)";
Name = "LPK25";
PNPDeviceID = "USB\\VID_09E8&PID_0076&MI_00\\6&383464A1&0&0000";
Service = "usbaudio";
Status = "OK";
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "COMPUTER";
};
Device plugged: USB Composite Device
instance of Win32_PnPEntity
{
Caption = "USB Composite Device";
ClassGuid = "{36fc9e60-c465-11cf-8056-444553540000}";
CompatibleID = {"USB\\DevClass_00&SubClass_00&Prot_00", "USB\\DevClass_00&SubClass_00", "USB\\DevClass_00", "USB\\COMPOSITE"};
ConfigManagerErrorCode = 0;
ConfigManagerUserConfig = FALSE;
CreationClassName = "Win32_PnPEntity";
Description = "USB Composite Device";
DeviceID = "USB\\VID_09E8&PID_0076\\5&385A3465&0&2";
HardwareID = {"USB\\VID_09E8&PID_0076&REV_0100", "USB\\VID_09E8&PID_0076"};
Manufacturer = "(Standard USB Host Controller)";
Name = "USB Composite Device";
PNPDeviceID = "USB\\VID_09E8&PID_0076\\5&385A3465&0&2";
Service = "usbccgp";
Status = "OK";
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "COMPUTER";
};
显然,其中的 LPK25 是真实设备,而 USB 复合设备是一些伪实体。 对于鼠标,我得到四个实体。对于游戏控制器三等。 那么我如何判断其中哪一个是“真实的”呢?
I'm using a WMI query to receive events when USB devices are plugged or unplugged.
SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_USBControllerDevice'
From the received events I'm taking the Dependent
object to get a Win32_PnPEntity.
The problem is, for pretty much any physical device, there are at least two logical devices.
So I'm receiving data such as:
Device unplugged: LPK25
Device unplugged: USB Composite Device
Device plugged: LPK25
instance of Win32_PnPEntity
{
Caption = "LPK25";
ClassGuid = "{4d36e96c-e325-11ce-bfc1-08002be10318}";
CompatibleID = {"USB\\Class_01&SubClass_01&Prot_00", "USB\\Class_01&SubClass_01", "USB\\Class_01"};
ConfigManagerErrorCode = 0;
ConfigManagerUserConfig = FALSE;
CreationClassName = "Win32_PnPEntity";
Description = "USB Audio Device";
DeviceID = "USB\\VID_09E8&PID_0076&MI_00\\6&383464A1&0&0000";
HardwareID = {"USB\\VID_09E8&PID_0076&REV_0100&MI_00", "USB\\VID_09E8&PID_0076&MI_00"};
Manufacturer = "(Generic USB Audio)";
Name = "LPK25";
PNPDeviceID = "USB\\VID_09E8&PID_0076&MI_00\\6&383464A1&0&0000";
Service = "usbaudio";
Status = "OK";
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "COMPUTER";
};
Device plugged: USB Composite Device
instance of Win32_PnPEntity
{
Caption = "USB Composite Device";
ClassGuid = "{36fc9e60-c465-11cf-8056-444553540000}";
CompatibleID = {"USB\\DevClass_00&SubClass_00&Prot_00", "USB\\DevClass_00&SubClass_00", "USB\\DevClass_00", "USB\\COMPOSITE"};
ConfigManagerErrorCode = 0;
ConfigManagerUserConfig = FALSE;
CreationClassName = "Win32_PnPEntity";
Description = "USB Composite Device";
DeviceID = "USB\\VID_09E8&PID_0076\\5&385A3465&0&2";
HardwareID = {"USB\\VID_09E8&PID_0076&REV_0100", "USB\\VID_09E8&PID_0076"};
Manufacturer = "(Standard USB Host Controller)";
Name = "USB Composite Device";
PNPDeviceID = "USB\\VID_09E8&PID_0076\\5&385A3465&0&2";
Service = "usbccgp";
Status = "OK";
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "COMPUTER";
};
Obviously, the LPK25 of these is the real device, while the USB Composite Device is some pseudo-entity.
For a mouse, I get four entities. For a game controller three, etc.
So how do I figure out which one of them is the "real thing?"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我的理解,你造成了混乱,对我来说,你收到两个事件是正常的。这是因为出现了两个新物体。
usbccgp
是 USB 音频的低级驱动程序。我认为您必须按服务进行过滤,例如我使用 USB 密钥进行测试,并且有两个事件,一个用于
USBSTOR
(低级别),第二个用于disk(高级)。
In my understanding you are making a confusion, for me it's normal you receive two events. It's because two new objects appears.
usbccgp
is the low level driver for usb audio.I think that you have to filter by service, for example I test with a USB key and I've got two events, one for
USBSTOR
(low level) and a second fordisk
(high level).