Search code examples
c++windowsdrivers

How to get GPU information in C++ before the drivers are installed


We have a piece of software which can run on several different graphics cards, both ATI and NVIDIA. I need to be able to determine either the device id or the model name of the graphics card before its drivers are installed, so that I can create a hard drive image which can be booted up with any of the graphics cards we support, have it detect the graphics card on first boot, install the drivers then restart. Target platform is WinXP.

I tried using WMI but that can only retrieve information about the display adapter, which doesn't include the device id, and before the drivers are installed the display adapter will just has generic data like "Video Controller (VGA)" for the name and so on.

EnumDisplayDevices cannot detect the device until after its drivers are installed.

This must be possible, as when the new hardware wizard opens it knows the name of the graphics card, but I just can't find a way of doing it.

Any ideas?

EDIT - Here's the query

ExecQuery(bstr_t("WQL"),bstr_t("SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE 'PCI\\VEN'"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);

Solution

  • For future reference for other users I'll add my own answer.

    Contrary to what I said in my post, WMI can in fact detect uninstalled devices, by querying for Win32_PNPEntity you can get their device ids.