Skip to content

gh-152433: Windows: fix errors in sys.getwindowsversion() for UWP build#152604

Open
thexai wants to merge 1 commit into
python:mainfrom
thexai:windows-version
Open

gh-152433: Windows: fix errors in sys.getwindowsversion() for UWP build#152604
thexai wants to merge 1 commit into
python:mainfrom
thexai:windows-version

Conversation

@thexai

@thexai thexai commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@thexai

thexai commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

For more context, the actual issue with sys.getwindowsversion() is that return incorrect value in recent Windows 11 versions:

e.g: in Windows 11 25H2 return 10.0.26100 instead of correct 10.0.26200.

(but not directly observable because only is used as second fallback on platform module)

With this change, it will be possible use sys.getwindowsversion() as the first fallback (after WMI) and will also be compatible with UWP.

In UWP, it would be the primary method because WMI is not available and subprocess "cmd ver" is also not available.

Related to #129294

@thexai
thexai force-pushed the windows-version branch from 3e025ce to e641600 Compare July 23, 2026 09:19
@thexai thexai changed the title gh-152433: Windows: improve sys.getwindowsversion() use RtlGetVersion for Desktop gh-152433: Windows: improve sys.getwindowsversion(), use RtlGetVersion() and allow build for UWP Jul 23, 2026
@thexai
thexai force-pushed the windows-version branch from e641600 to 79ebd57 Compare July 23, 2026 09:25
@thexai
thexai force-pushed the windows-version branch from 79ebd57 to a23a7a4 Compare July 23, 2026 13:48
Comment thread Python/sysmodule.c Outdated
@thexai
thexai force-pushed the windows-version branch from a23a7a4 to fdb6a9c Compare July 24, 2026 15:26
@thexai

thexai commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Updated with alternative fix:

    // Obtain the build number from Windows registry in case of Windows 10/11
    if (realMajor == 10 && realMinor == 0) {
        wchar_t currentBuild[32] = {0};
        DWORD len = sizeof(currentBuild);
        if (ERROR_SUCCESS == RegGetValueW(HKEY_LOCAL_MACHINE, REG_CURRENT_VERSION, L"CurrentBuild",
            RRF_RT_REG_SZ, NULL, &currentBuild, &len))
        {
            realBuild = _wtol(currentBuild);
        }
    }

@thexai thexai changed the title gh-152433: Windows: improve sys.getwindowsversion(), use RtlGetVersion() and allow build for UWP gh-152433: Windows: improve sys.getwindowsversion(), fix return incorrect build number for Windows 11+ and fix errors in UWP Jul 24, 2026
@zooba

zooba commented Jul 24, 2026

Copy link
Copy Markdown
Member

the point of this API is to find out what OS features are available, and if you're under compatibility shims, they may not be. In that case, getting the "real" version is going to be a lie.

So the right answer to "what version should I assume is running" is the one that GetVersion returns.

@thexai
thexai force-pushed the windows-version branch from fdb6a9c to 5dab92e Compare July 24, 2026 18:32
@thexai

thexai commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Okay, we'll take it one step at a time...

@thexai thexai changed the title gh-152433: Windows: improve sys.getwindowsversion(), fix return incorrect build number for Windows 11+ and fix errors in UWP gh-152433: Windows: fix errors in sys.getwindowsversion() for UWP build Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants