Why does SetupDiEnumDriverInfo give two version numbers for my driver

后端 未结 2 590
北海茫月
北海茫月 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.

    0 讨论(0)
  • 2021-01-05 12:29

    As your code is written, all the possible drivers will be output. Try doing the following to filter on only the installed driver:

    SP_DEVINSTALL_PARAMS InstallParams;
    if ( !SetupDiGetDeviceInstallParams( devInfoSet, &devInfo, &InstallParams ) )
    {
       //Error
    }
    else
    {
       InstallParams.FlagsEx |= DI_FLAGSEX_INSTALLEDDRIVER;
       if ( !SetupDiSetDeviceInstallParams( devInfoSet, &devInfo, &InstallParams) )
       {
          //Errror
       }
    }
    

    I found this at http://doxygen.reactos.org/df/db2/dll_2win32_2devmgr_2misc_8c_a1cd0b33c1785392a37689433dc99e482.html

    0 讨论(0)
提交回复
热议问题