Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current Windows 11 release in Python

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
like image 637
Pedro Avatar asked Mar 02 '26 20:03

Pedro


2 Answers

The solution I used is the following:

def is_win11():
    return sys.getwindowsversion().build >= 22000

And to know which type of Windows you have (e.g. Entreprise), you can use platform.win32_edition().

like image 199
Pedro Avatar answered Mar 05 '26 10:03

Pedro


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".

like image 27
Peter Badida Avatar answered Mar 05 '26 09:03

Peter Badida



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!