title: Resolving hierarchy of Win32_PnPEntities in WMI
body: <p>I'm using a WMI query to receive events when USB devices are plugged or unplugged.</p>
  
  <pre><code>SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_USBControllerDevice'
  </code></pre>
  
  <p>From the received events I'm taking the <code>Dependent</code> object to get a Win32_PnPEntity.</p>
  
  <p>The problem is, for pretty much any physical device, there are at least two logical devices.
  So I'm receiving data such as:</p>
  
  <pre><code>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&amp;SubClass_01&amp;Prot_00", "USB\\Class_01&amp;SubClass_01", "USB\\Class_01"};
          ConfigManagerErrorCode = 0;
          ConfigManagerUserConfig = FALSE;
          CreationClassName = "Win32_PnPEntity";
          Description = "USB Audio Device";
          DeviceID = "USB\\VID_09E8&amp;PID_0076&amp;MI_00\\6&amp;383464A1&amp;0&amp;0000";
          HardwareID = {"USB\\VID_09E8&amp;PID_0076&amp;REV_0100&amp;MI_00", "USB\\VID_09E8&amp;PID_0076&amp;MI_00"};
          Manufacturer = "(Generic USB Audio)";
          Name = "LPK25";
          PNPDeviceID = "USB\\VID_09E8&amp;PID_0076&amp;MI_00\\6&amp;383464A1&amp;0&amp;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&amp;SubClass_00&amp;Prot_00", "USB\\DevClass_00&amp;SubClass_00", "USB\\DevClass_00", "USB\\COMPOSITE"};
          ConfigManagerErrorCode = 0;
          ConfigManagerUserConfig = FALSE;
          CreationClassName = "Win32_PnPEntity";
          Description = "USB Composite Device";
          DeviceID = "USB\\VID_09E8&amp;PID_0076\\5&amp;385A3465&amp;0&amp;2";
          HardwareID = {"USB\\VID_09E8&amp;PID_0076&amp;REV_0100", "USB\\VID_09E8&amp;PID_0076"};
          Manufacturer = "(Standard USB Host Controller)";
          Name = "USB Composite Device";
          PNPDeviceID = "USB\\VID_09E8&amp;PID_0076\\5&amp;385A3465&amp;0&amp;2";
          Service = "usbccgp";
          Status = "OK";
          SystemCreationClassName = "Win32_ComputerSystem";
          SystemName = "COMPUTER";
  };
  </code></pre>
  
  <p>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?"</p>