Skip to content

Commit 766f1f5

Browse files
committed
Improving system.version_number for 10+ by taking build number into account
1 parent 57bcbca commit 766f1f5

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

tests/test_system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def test_version(self):
1313

1414
def test_version_name(self):
1515
assert is_unicode(windows.system.version_name)
16+
assert u"unknown" not in windows.system.version_name.lower()
1617

1718
def test_version_product_type(self):
1819
assert windows.system.product_type
@@ -26,7 +27,6 @@ def test_version_windir(self):
2627
def test_version_versionstr(self):
2728
assert is_unicode(windows.system.windir)
2829

29-
3030
def test_computer_name(self):
3131
computer_name = windows.system.computer_name
3232
assert computer_name

windows/winobject/system.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,40 @@ def version(self):
260260
result = tuple(result_tup[:2])
261261
return result
262262

263+
264+
265+
WINDOWS_10_BUILD_NUMBER_VERSION = {
266+
# (build_number, is_workstation): "version_name"
267+
(10240, True): "Windows 10 Version 1507",
268+
(10586, True): "Windows 10 Version 1511",
269+
(14393, True): "Windows 10 Version 1607",
270+
(15063, True): "Windows 10 Version 1703",
271+
(16299, True): "Windows 10 Version 1709",
272+
(17134, True): "Windows 10 Version 1803",
273+
(17763, True): "Windows 10 Version 1809",
274+
(18362, True): "Windows 10 Version 1903",
275+
(18363, True): "Windows 10 Version 1909",
276+
(19041, True): "Windows 10 Version 2004",
277+
(19042, True): "Windows 10 Version 20H2",
278+
(19043, True): "Windows 10 Version 21H1",
279+
(19044, True): "Windows 10 Version 21H2",
280+
(19045, True): "Windows 10 Version 22H2",
281+
(22000, True): "Windows 11 Version 21H2",
282+
(22621, True): "Windows 11 Version 22H2",
283+
(22631, True): "Windows 11 Version 23H2",
284+
(26100, True): "Windows 11 Version 24H2",
285+
286+
(14393, False): "Windows Server 2016",
287+
(17763, False): "Windows Server 2019",
288+
(20348, False): "Windows Server 2022",
289+
}
290+
291+
def _get_version_name_for_10_build(self, build_number, is_workstation):
292+
try:
293+
return self.WINDOWS_10_BUILD_NUMBER_VERSION[(build_number, is_workstation)]
294+
except KeyError as e:
295+
return u"Unknown Windows 10+ <versionstr={0} | is_workstation={1}>".format(self.versionstr, is_workstation)
296+
263297
@utils.fixedpropety
264298
def version_name(self):
265299
"""The name of the system version, values are:
@@ -280,14 +314,15 @@ def version_name(self):
280314
* Windows Server 2003
281315
* Windows XP
282316
* Windows 2000
283-
* "Unknow Windows <version={0} | is_workstation={1}>".format(version, is_workstation)
317+
* "Unknown Windows <version={0} | is_workstation={1}>".format(version, is_workstation)
284318
285319
:type: :class:`str`
286320
"""
287321
version = self.version
288322
is_workstation = self.product_type == gdef.VER_NT_WORKSTATION
289323
if version == (10, 0):
290-
return [u"Windows Server 2016", u"Windows 10"][is_workstation]
324+
return self._get_version_name_for_10_build(self.build_number, is_workstation)
325+
# return [u"Windows Server 2016", u"Windows 10"][is_workstation]
291326
elif version == (6, 3):
292327
return [u"Windows Server 2012 R2", u"Windows 8.1"][is_workstation]
293328
elif version == (6, 2):
@@ -312,7 +347,7 @@ def version_name(self):
312347
elif version == (5, 0):
313348
return u"Windows 2000"
314349
else:
315-
return u"Unknow Windows <version={0} | is_workstation={1}>".format(version, is_workstation)
350+
return u"Unknown Windows <version={0} | is_workstation={1}>".format(version, is_workstation)
316351

317352
VERSION_MAPPER = gdef.FlagMapper(gdef.VER_NT_WORKSTATION, gdef.VER_NT_DOMAIN_CONTROLLER, gdef.VER_NT_SERVER)
318353
@utils.fixedpropety

0 commit comments

Comments
 (0)