Commit 11f8b9db authored by Brian Curtin's avatar Brian Curtin

Fix #7863. Properly identify Windows 7 and Server 2008 R2.

Removed various unused code and added a way to correctly determine
server vs. workstation via the registry.
parent ca485624
...@@ -603,12 +603,19 @@ def win32_ver(release='',version='',csd='',ptype=''): ...@@ -603,12 +603,19 @@ def win32_ver(release='',version='',csd='',ptype=''):
VER_PLATFORM_WIN32_WINDOWS = 1 VER_PLATFORM_WIN32_WINDOWS = 1
VER_PLATFORM_WIN32_NT = 2 VER_PLATFORM_WIN32_NT = 2
VER_NT_WORKSTATION = 1 VER_NT_WORKSTATION = 1
VER_NT_SERVER = 3
REG_SZ = 1
# Find out the registry key and some general version infos # Find out the registry key and some general version infos
maj,min,buildno,plat,csd = GetVersionEx() winver = GetVersionEx()
maj,min,buildno,plat,csd = winver
version = '%i.%i.%i' % (maj,min,buildno & 0xFFFF) version = '%i.%i.%i' % (maj,min,buildno & 0xFFFF)
if csd[:13] == 'Service Pack ': if hasattr(winver, "service_pack"):
csd = 'SP' + csd[13:] if winver.service_pack != "":
csd = 'SP%s' % winver.service_pack_major
else:
if csd[:13] == 'Service Pack ':
csd = 'SP' + csd[13:]
if plat == VER_PLATFORM_WIN32_WINDOWS: if plat == VER_PLATFORM_WIN32_WINDOWS:
regkey = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion' regkey = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion'
...@@ -639,23 +646,33 @@ def win32_ver(release='',version='',csd='',ptype=''): ...@@ -639,23 +646,33 @@ def win32_ver(release='',version='',csd='',ptype=''):
else: else:
release = 'post2003' release = 'post2003'
elif maj == 6: elif maj == 6:
if min == 0: if hasattr(winver, "product_type"):
# Per http://msdn2.microsoft.com/en-us/library/ms724429.aspx product_type = winver.product_type
else:
product_type = VER_NT_WORKSTATION
# Without an OSVERSIONINFOEX capable sys.getwindowsversion(),
# or help from the registry, we cannot properly identify
# non-workstation versions.
try: try:
productType = GetVersionEx(1)[8] key = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey)
except TypeError: name, type = RegQueryValueEx(key, "ProductName")
# sys.getwindowsversion() doesn't take any arguments, so # Discard any type that isn't REG_SZ
# we cannot detect 2008 Server that way. if type == REG_SZ and name.find("Server") != -1:
# XXX Add some other means of detecting 2008 Server ?! product_type = VER_NT_SERVER
except WindowsError:
# Use default of VER_NT_WORKSTATION
pass
if min == 0:
if product_type == VER_NT_WORKSTATION:
release = 'Vista' release = 'Vista'
else: else:
if productType == VER_NT_WORKSTATION: release = '2008Server'
release = 'Vista' elif min == 1:
else: if product_type == VER_NT_WORKSTATION:
release = '2008Server' release = '7'
#elif min == 1: else:
# # Windows 7 release candidate uses version 6.1.7100 release = '2008ServerR2'
# release = '7RC'
else: else:
release = 'post2008Server' release = 'post2008Server'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment