Why does GetFileVersionInfo on kernel32.dll in Windows 10 return version 6.2?

百般思念 提交于 2019-12-12 07:18:29

问题


I am trying to retrieve kernel32.dll version in order to perform a Windows version check. Yet, for some reason, even though kernel32.dll's version (as seen in file properties) is 10.0.10586.0, the returned version is: 6.2.10586.0 how come?

    DWORD dwDummy;
    DWORD dwFVISize = GetFileVersionInfoSize(lpszFilePath, &dwDummy);
    LPBYTE lpVersionInfo = new BYTE[dwFVISize];
    if (GetFileVersionInfo(lpszFilePath, 0, dwFVISize, lpVersionInfo) == 0)
    {
        return FALSE;
    }

    UINT uLen;
    VS_FIXEDFILEINFO *lpFfi;
    BOOL bVer = VerQueryValue(lpVersionInfo, L"\\", (LPVOID *)&lpFfi, &uLen);

    if (!bVer || uLen == 0)
    {
        return FALSE;
    }
    DWORD dwFileVersionMS = lpFfi->dwFileVersionMS;
    DWORD dwFileVersionLS = lpFfi->dwFileVersionLS;
    delete[] lpVersionInfo;

    DWORD dwLeftMost = HIWORD(dwFileVersionMS);
    DWORD dwSecondLeft = LOWORD(dwFileVersionMS);
    DWORD dwSecondRight = HIWORD(dwFileVersionLS);
    DWORD dwRightMost = LOWORD(dwFileVersionLS);

Kernel32.dll properties (same as in SysWow64):


回答1:


You are reading the wrong fields from the version information for this task. Instead of dwFileVersionMS and dwFileVersionLS use dwProductVersionMS and dwProductVersionLS.

The file version fields are subject to supportedOS compatibility issues. That is their values depend on the supportedOS levels declared in your application manifest. On the other hand the product version fields do not depend on the manifest.




回答2:


Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2).

this is from GetVersionEx function MSDN description. for GetFileVersionInfo no such note, but really this doing same. i look under debugger:

so 10.0 ( 0xA000) in dwFileVersionMS can be fixed to 6.2 or 6.3 but dwProductVersionMS - not changed (0xA000 ~ 10.0) think need fix MSDN documentation for GetFileVersionInfo[Ex] :)



来源:https://stackoverflow.com/questions/38068477/why-does-getfileversioninfo-on-kernel32-dll-in-windows-10-return-version-6-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!