Reputation: 2943
I want to get Windows build version. I have searched everywhere for this, but to no avail.
No, I don't want to know if it's 7, 8, 10, or whatever. I don't want the Windows build number. I want to know the Windows build version (1507, 1511, 1607, etc.)
I am not sure what the official name of this would be, but here is an image of what I'm asking for:
I tried using the sys
, os
and platform
modules, but I can't seem to find anything built-in that can do this.
Upvotes: 8
Views: 9068
Reputation: 6298
It seems you are looking for the ReleaseID
which is different from the build number.
You can find it by query the value of ReleaseID
in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
registry key.
You can query the value using winreg
module:
import winreg
def getReleaseId():
key = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion"
val = r"ReleaseID"
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key) as key:
releaseId = int(winreg.QueryValueEx(key,val)[0])
return releaseId
or REG command:
import os
def getReleaseId():
key = r"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
val = r"ReleaseID"
output = os.popen( 'REG QUERY "{0}" /V "{1}"'.format( key , val) ).read()
releaseId = int( output.strip().split(' ')[-1] )
return releaseId
Upvotes: 4
Reputation: 31930
The build number is sufficient and can be found with:
sys.getwindowsversion().build
or the platform module. Match the build with the table at this link to determine the ReleaseId
you'd like to target:
In this case 1511
corresponds to TH2 and build 10586
:
# 1511 Threshold 2 November 10, 2015 10586
Upvotes: 3
Reputation: 6298
You can use ctypes and GetVersionEx from Kernel32.dll
to find the build number.
import ctypes
def getWindowsBuild():
class OSVersionInfo(ctypes.Structure):
_fields_ = [
("dwOSVersionInfoSize" , ctypes.c_int),
("dwMajorVersion" , ctypes.c_int),
("dwMinorVersion" , ctypes.c_int),
("dwBuildNumber" , ctypes.c_int),
("dwPlatformId" , ctypes.c_int),
("szCSDVersion" , ctypes.c_char*128)];
GetVersionEx = getattr( ctypes.windll.kernel32 , "GetVersionExA")
version = OSVersionInfo()
version.dwOSVersionInfoSize = ctypes.sizeof(OSVersionInfo)
GetVersionEx( ctypes.byref(version) )
return version.dwBuildNumber
Upvotes: 2
Reputation: 1
I don't know of any libraries that will give you this value directly, but you can parse the command window output when you open a new command window via os.popen()
.
print(os.popen('cmd').read())
The boot screen for the command window has the version/build data on the first line. I'm running version 6.1, build 7601, according to the following output from os.popen()
:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\...>
And when I run winver
, I see that I'm running Windows 7, Version 6.1, Build 7601: SP1:
Which ties to the interpretation of the first line in the output from os.popen()
.
Upvotes: -3