How to get "FriendlyName" of a Device ContainerID (SPDRP_BASE_CONTAINERID)

Greg Visser 11 Reputation points
2020-12-14T18:30:55.63+00:00

I want to get the "FriendlyName" of a device containerID.

For example, when you open Device Manager, View => Devices By Container, each container has a friendly name. I can get the container GUID, but do not know how to get the friendly name. In the picture below, you can see the "Logitech Unifying Receiver" container name that contains all the HID devices.

47940-logitech.png

To get the Container ID GUID to list all associated devices, i'm using SetupDi

eg:

Guid guid = Guid.Empty;  
IntPtr infoList = SetupDiGetClassDevs(ref guid, null, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES);  
  
for (uint i = 0; SetupDiEnumDeviceInfo(infoList, i, out spDevInfo); i++)  
{  
    if (SetupDiGetDeviceRegistryPropertyW(infoList, ref spDevInfo,   
SPDRP_BASE_CONTAINERID, out _, sb, BUFSIZE, out _))  
    {  
          dev.ContainerId = sb.ToString();  
     }  
}  

dev.ContainerId will now be a unique GUID.

Using this containerid, I'm able to group all the devices that belong to this container. I cannot find how to retreive the friendly name of this container (such as the "Logitech Unifying Receiver")

Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,541 questions
0 comments No comments
{count} vote

7 answers

Sort by: Most helpful
  1. Sam [MSFT] 11 Reputation points Microsoft Employee
    2021-01-04T23:24:29.75+00:00

    In PnP's object model, 1 device container object can contain 1...n devnode objects. The way to reference the container object is the container ID property on the devnode. The next question is how to discover the container object. You can't with the old SetupDi APIs. You can with either the Winodws.Devices.Enumeration WinRT API or DevQuery C-style API. Winodws.Devices.Enumeration is built on top of DevQuery.

    Here is the sample for Windows.Devices.Enumeration:
    https://github.com/microsoft/Windows-universal-samples/tree/master/Samples/DeviceEnumerationAndPairing

    The basic idea of the API is you declaratively ask for what you want upfront.
    Like: I want

    • device container objects.
    • based on a selection criteria (eg. its container ID == foo)
    • and, I want the following properties off of the object (in the WinRT version, the friendly name is already on the base object)

    DevQuery is fundamentally async, but there are both sync and async versions of the query APIs.

    BTW, you might as well do the initial devnode enumeration with these APIs as well.

    Make sure you are using the DEVPKEY_Device_ContainerId key, and not the base container ID to find the device container object. They are often the same, but not always.
    https://learn.microsoft.com/en-us/windows-hardware/drivers/install/devpkey-device-containerid

    2 people found this answer helpful.
    0 comments No comments

  2. Greg Visser 11 Reputation points
    2021-01-11T14:56:27.957+00:00

    Hi Samad,

    Thanks for the information. I'll likely use the Windows.Devices.Enumeration libraries to accomplish my task. Is this API compatible with Windows 7?

    I wasn't able to find the DevQuery API you mentioned. Can you point me towards where this API is documented? Or is the Windows.Device.Enumeration source code available somewhere?

    1 person found this answer helpful.
    0 comments No comments

  3. ABDUS SAMAD 0 Reputation points
    2023-11-23T23:05:29.05+00:00

    How can I get my Microsoft hybrid learning certification

    0 comments No comments

  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  5. ABDUS SAMAD 0 Reputation points
    2023-11-23T23:06:36.1766667+00:00

    Email samadtni@gmail.com

    0 comments No comments