解析 WMI 中 Win32_PnPEtities 的层次结构

发布于 2024-12-25 09:33:50 字数 2385 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぽ尐不点ル 2025-01-01 09:33:50

根据我的理解,你造成了混乱,对我来说,你收到两个事件是正常的。这是因为出现了两个新物体。

  1. 低级对象 usbccgp 是 USB 音频的低级驱动程序。
  2. 支持音频硬件的高级对象。

我认为您必须按服务进行过滤,例如我使用 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.

  1. The low level object for you usbccgp is the low level driver for usb audio.
  2. The high level object that support your audio hardware.

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 for disk(high level).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文