SetupDiGetClassDevs returns an empty list even when configured not to filter by GUID, is there an alternative way to get the info list?

Nadav Reichler 20 Reputation points
2023-06-04T13:45:36.5366667+00:00

I tried configuring the function not to filter by GUID like this:

SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES)

but still the dev info list is empty.

Is this a known issue? is there an alternative way to get the info list?

Windows for business Windows Client for IT Pros Devices and deployment Other
Developer technologies C++
{count} votes

Accepted answer
  1. RLWA32 49,536 Reputation points
    2023-06-04T18:53:22.2666667+00:00

    SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES)

    The posted question asked about the above SetupApi function call. I could not reproduce the Questioner's issue when I used the following:

    #include <Windows.h>
    #include <SetupAPI.h>
    #pragma comment(lib, "setupapi")
    #define INITGUID
    #include <guiddef.h>
    #include <devpkey.h>
    
    #include <stdio.h>
    #include <tchar.h>
    
    int wmain()
    {
        auto hSet = SetupDiGetClassDevsW(NULL, NULL, NULL, DIGCF_ALLCLASSES);
        if (hSet != INVALID_HANDLE_VALUE)
        {
            SP_DEVINFO_DATA spdd{ sizeof spdd};
            DWORD ndx{ 0 };
            DWORD err{ ERROR_SUCCESS };
    
            while(err != ERROR_NO_MORE_ITEMS)
            {
                if (SetupDiEnumDeviceInfo(hSet, ndx, &spdd))
                {
                    WCHAR szGuid[39]{};
                    WCHAR szName[512]{};
                    DEVPROPTYPE proptype{};
    
                    StringFromGUID2(spdd.ClassGuid, szGuid, ARRAYSIZE(szGuid));
                    if (SetupDiGetDevicePropertyW(hSet, &spdd, &DEVPKEY_NAME, &proptype, (PBYTE)szName, sizeof szName, NULL, 0))
                        wprintf_s(L"%u. Class GUID is %s, name is %s\n", ndx, szGuid, szName);
                    else
                        wprintf_s(L"SetupDiGetDevicePropertyW for index %u failed with %u\n", ndx, GetLastError());
    
                    ++ndx;
                }
                else
                {
                    err = GetLastError();
                    if (err != ERROR_NO_MORE_ITEMS)
                    {
                        wprintf_s(L"Device enumeration for index %u failed with %u\n", ndx, err);
                        ++ndx;
                    }
                }
            }
    
            wprintf_s(L"Enumerated %u devices\n", ndx);
    
            SetupDiDestroyDeviceInfoList(hSet);
        }
    
        return 0;
    }
    

    The code snippet that the Questioner posted was incomplete and diverged from the posted question and so it was ignored.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.