registrywindows-10

HKLM\Software\Microsoft\Windows NT\CurrentVersion: What's the difference between CurrentBuild and CurrentBuildNumber?


I'm writing code to reliably determine the Windows 10 build number by checking the registry, and I have a question about those two registry keys:

Screenshot of regedit

Both seem to contain the Windows 10 build number (10240 for RTM/TH1, 10586 for 1511/TH2).

Is there any (documented) difference between those two? Which one should I use to determine the "Version" of Windows 10?


Footnote: I am aware that *usually* checking for required features is better practice than checking version numbers. Note, however, that there are legitimate cases for wanting to get the version of the currently running OS, which I'll gladly discuss in the comments, if needed.

Solution

  • I noticed a clear difference between them.

    For Win32 programs in compatibility mode, attempting to read the value of CurrentBuild via the Win32 API will return the actual system build number, while reading CurrentBuildNumber will return a fake build number that matches the compatibility settings.

    I verified this using a simple C++ program:

    #include <windows.h>
    #include <iostream>
    
    int main() {
        wchar_t value[256];
        DWORD value_length;
    
        HKEY hKey;
        if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
            value_length = sizeof(value);
            if (RegQueryValueExW(hKey, L"CurrentBuild", nullptr, nullptr, (LPBYTE) value, &value_length) == ERROR_SUCCESS) {
                std::wcout << L"CurrentBuild: " << value << std::endl;
            }
    
            value_length = sizeof(value);
            if (RegQueryValueExW(hKey, L"CurrentBuildNumber", nullptr, nullptr, (LPBYTE) value, &value_length) == ERROR_SUCCESS) {
                std::wcout << L"CurrentBuildNumber: " << value << std::endl;
            }
    
            RegCloseKey(hKey);
        }
        return 0;
    }
    

    My actual system version is 10.0.26220.7051.

    When I run this program directly, it prints

    CurrentBuild: 26220
    CurrentBuildNumber: 26220
    

    However, if I enable compatibility mode for this .exe file and set the compatibility target to Windows 7, then running it will print

    CurrentBuild: 26220
    CurrentBuildNumber: 7600
    

    Then set the compatibility target to Windows 8, and it will print

    CurrentBuild: 26220
    CurrentBuildNumber: 9200