Get Windows Version In Python
Solution 1:
you can use platform module
import platform
print(platform.platform())
print(platform.system())
print(platform.release())
print(platform.version())
print(platform.version().split('.')[2])
print(platform.machine())
output:
Windows-10-10.0.19041-SP0
Windows
10
10.0.19041
19041
AMD64
Solution 2:
You can make use of the sys library, it has a command just for this. Python Docs on sys
import sys
version = sys.getwindowsversion()
print(version)
print(version[2]) # You can directly reference the build element by index numberprint(version.build) # Or by name
Output:
sys.getwindowsversion(major=10, minor=0, build=19042, platform=2, service_pack='')
19042
19042
Solution 3:
To put a string inside a string without getting sinttax error you should use single quotes. The code would look like this:
import osos.system("Reg Query 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion' /v ReleaseId")
input()
Solution 4:
The only registry entry I was able to find that contains the 20H2
value on my system was
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DisplayVersion
Displayversion
is also a REG_SZ value.
Unfortunately I don't know since which Windows 10 version this entry exists. I found some info that on older Windows 10 installations this key was an optional 32bit DWORD value that could be used to show build info, edition, WinDir path on the desktop.
But this is definitely the location where winver
gets the version info from. If you modify the string winver also shows the modified value.
Post a Comment for "Get Windows Version In Python"