Fixes platform.win32_ver on non-Windows platforms (GH-12912)
(cherry picked from commit d307d05350
)
Co-authored-by: Steve Dower <steve.dower@microsoft.com>
This commit is contained in:
parent
36aecc0079
commit
9344d74f7b
|
@ -535,10 +535,6 @@ def win32_ver(release='', version='', csd='', ptype=''):
|
||||||
from sys import getwindowsversion
|
from sys import getwindowsversion
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return release, version, csd, ptype
|
return release, version, csd, ptype
|
||||||
try:
|
|
||||||
from winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE
|
|
||||||
except ImportError:
|
|
||||||
from _winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE
|
|
||||||
|
|
||||||
winver = getwindowsversion()
|
winver = getwindowsversion()
|
||||||
maj, min, build = winver.platform_version or winver[:3]
|
maj, min, build = winver.platform_version or winver[:3]
|
||||||
|
@ -564,16 +560,20 @@ def win32_ver(release='', version='', csd='', ptype=''):
|
||||||
_WIN32_SERVER_RELEASES.get((maj, None)) or
|
_WIN32_SERVER_RELEASES.get((maj, None)) or
|
||||||
release)
|
release)
|
||||||
|
|
||||||
key = None
|
|
||||||
try:
|
try:
|
||||||
key = OpenKeyEx(HKEY_LOCAL_MACHINE,
|
try:
|
||||||
r'SOFTWARE\Microsoft\Windows NT\CurrentVersion')
|
import winreg
|
||||||
ptype = QueryValueEx(key, 'CurrentType')[0]
|
except ImportError:
|
||||||
except:
|
import _winreg as winreg
|
||||||
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
finally:
|
else:
|
||||||
if key:
|
try:
|
||||||
CloseKey(key)
|
cvkey = r'SOFTWARE\Microsoft\Windows NT\CurrentVersion'
|
||||||
|
with winreg.OpenKeyEx(HKEY_LOCAL_MACHINE, cvkey) as key:
|
||||||
|
ptype = QueryValueEx(key, 'CurrentType')[0]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
return release, version, csd, ptype
|
return release, version, csd, ptype
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue