Why does SetupDiEnumDriverInfo give two version numbers for my driver

后端 未结 2 609
北海茫月
北海茫月 2021-01-05 12:09

I\'m trying to get the version number of a driver programmatically. The seems to be done by using SetupDiEnumDriverInfo to get a SP_DRVINFO_DATA st

2条回答
  •  感动是毒
    2021-01-05 12:19

    I find the solution very complicated: SetupDiBuildDriverInfoList, SetupDiEnumDriverInfo, SetupDiGetDeviceInstallParams, SetupDiSetDeviceInstallParams.

    There is another option to get the version of only the driver which is currently in use although there are multiple drivers installed.

    With

    SetupDiGetDeviceRegistryProperty(devInfoSet, &devInfo, SPDRP_DRIVER, 
                                     NULL, (BYTE*)UnicodeBuf, BufferSize, NULL);
    

    I obtain the driver path in the registry which looks like this:

    "{4D36E978-E325-11CE-BFC1-08002BE10318}\0000"
    

    I load this into a variable s_DriverPath and then I read the driver version directly from HKEY_LOCAL_MACHINE:

    CString s_RegPath = L"SYSTEM\\CurrentControlSet\\Control\\Class\\" + s_DriverPath;
    

    The key "DriverVersion" returns the version of the currently used driver. When you update the driver to a newer version Windows adapts all the registry entries automatically. So this way you always get the currently used driver version.

    There is more info which you can read about the driver. The entry "DriverDateData" are 8 bytes which contain the driver date as FILETIME. All this information comes from the INF file.

    This works from Windows XP until Windows 10.

提交回复
热议问题