Get current Windows 11 release in Python

Question:

In Python 3.8.10 i cannot get the correct Windows release, i’m running Windows 11 Insider Preview, but the output says it Windows 10

Bug

Any WorkAround?

Edit: for now the only way i found to detect W11 is with

wmic os get name
Asked By: Pedro

||

Answers:

The platform.release() call traces to win32_ver() which then calls the C function sys_getwindowsversion_impl().

That C call simply pulls the version of kernel32.dll file i.e. not of the Windows itself by utilizing the GetFileVersionInfoW() + VerQueryValueW() Win32 API functions.

So until kernel32.dll file’s version changes it’ll remain Windows 10. Check manually if the result matches on that system and if it does not, open a bug for CPython.

Regarding whether this is the correct implementation or not I’d say is debatable. Apparently it was in the past but now it’s not, so I guess just use ctypes for GetProductInfo() or pull it from the registry.

However, you are using a preview version, which is one of the reasons the version might be "incorrect" because perhaps the Windows developers intend it to still be 10 instead of 11 and somewhere in the system there’s a flag saying it’s a "10" + "preview".

Answered By: Peter Badida

the solution i ended up following:

def IsWin11():
    if sys.getwindowsversion().build > 22000:return True
    else:return False
Answered By: Pedro
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.