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

Greg Visser 11 Reputation points

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.


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


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,   
          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,567 questions
0 comments No comments
{count} vote

7 answers

Sort by: Most helpful
  1. Sam [MSFT] 11 Reputation points Microsoft Employee

    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:

    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.

    2 people found this answer helpful.
    0 comments No comments

  2. Greg Visser 11 Reputation points

    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

    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


    0 comments No comments