WMI Query Parent/Children of PNP_entity
Asked Answered
L

2

11

I am currently developing a program to check if a USB device has been detected on a specific USB hub in C#. I know the PID and VID of both the hub and the slave device connected to the hub. I am doing this using a ManagementObjectSearcher Query to get the devices:

ManagementObjectSearcher USBSearchQuery = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE \"%VID_17EF&PID_6019%\"");
ManagementObjectCollection DeviceCollection = USBSearchQuery.Get();

This works quite fine. The ManagementObjectCollection DeviceCollection contains 2 elements. One HID device and one USB device. When I check with the device manager, I see the elements and can access the property Parent, but it seems to be impossible to get either the parent or the children of an object through a WMI query.

I could do this either through the children of the hub or the parent of the device. Do any of you have an idea how to do this?

Liturgist answered 28/7, 2015 at 13:25 Comment(1)
I know this is a long time ago but did you ever find the solution to this ? I'm having the exact same use case !Kusin
P
0
ManagementObjectCollection DeviceCollection = USBSearchQuery .Get();
foreach (ManagementObject mo in DeviceCollection )
    {
      //get all properties 
      //ex: mo.Properties["Description"].Value represents the friendly name of the device
      //mo.Properties["PNPClass"].Value represents the parent class of the device
    }
Petcock answered 23/4, 2019 at 14:30 Comment(1)
The question was about the parent device (by connection), not the parent class.Panjabi

© 2022 - 2024 — McMap. All rights reserved.