Skip to content

Commit 947093c

Browse files
authored
Merge pull request #69 from hakril/improve_version_name
Improve `windows.system.version_name`
2 parents 57bcbca + 0c9c7d3 commit 947093c

2 files changed

Lines changed: 74 additions & 8 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: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,77 @@ def version(self):
260260
result = tuple(result_tup[:2])
261261
return result
262262

263+
# Based on:
264+
# https://jrsoftware.org/ishelp/index.php?topic=winvernotes
265+
# https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions
266+
267+
WINDOWS_10_BUILD_NUMBER_VERSION = {
268+
# (build_number, is_workstation): "version_name"
269+
(10240, True): u"Windows 10 Version 1507",
270+
(10586, True): u"Windows 10 Version 1511",
271+
(14393, True): u"Windows 10 Version 1607",
272+
(15063, True): u"Windows 10 Version 1703",
273+
(16299, True): u"Windows 10 Version 1709",
274+
(17134, True): u"Windows 10 Version 1803",
275+
(17763, True): u"Windows 10 Version 1809",
276+
(18362, True): u"Windows 10 Version 1903",
277+
(18363, True): u"Windows 10 Version 1909",
278+
(19041, True): u"Windows 10 Version 2004",
279+
(19042, True): u"Windows 10 Version 20H2",
280+
(19043, True): u"Windows 10 Version 21H1",
281+
(19044, True): u"Windows 10 Version 21H2",
282+
(19045, True): u"Windows 10 Version 22H2",
283+
(22000, True): u"Windows 11 Version 21H2",
284+
(22621, True): u"Windows 11 Version 22H2",
285+
(22631, True): u"Windows 11 Version 23H2",
286+
(26100, True): u"Windows 11 Version 24H2",
287+
288+
(14393, False): u"Windows Server 2016",
289+
# 16299 : Windows Server, version 1709 ?
290+
# 17134 : Windows Server, version 1803 ?
291+
# 17134 : Windows Server, version 1803 ?
292+
(17763, False): u"Windows Server 2019",
293+
# 18362 : Windows Server, version 1903 ?
294+
# 18363 : Windows Server, version 1909 ?
295+
# 19041 : Windows Server, version 2004 ?
296+
# 19042 : Windows Server, version 20H2 ?
297+
(20348, False): u"Windows Server 2022",
298+
# 25398 : Windows Server, version 23H2 ?
299+
(26100, False): u"Windows Server 2025",
300+
}
301+
302+
def _get_version_name_for_10_build(self, build_number, is_workstation):
303+
try:
304+
return self.WINDOWS_10_BUILD_NUMBER_VERSION[(build_number, is_workstation)]
305+
except KeyError as e:
306+
return u"Unknown Windows 10+ <versionstr={0} | is_workstation={1}>".format(self.versionstr, is_workstation)
307+
263308
@utils.fixedpropety
264309
def version_name(self):
265310
"""The name of the system version, values are:
266311
312+
* Windows Server 2025
313+
* Windows 11 Version 24H2
314+
* Windows 11 Version 23H2
315+
* Windows 11 Version 22H2
316+
* Windows 11 Version 21H2
317+
* Windows 10 Version 22H2
318+
* Windows 10 Version 21H2
319+
* Windows Server 2022
320+
* Windows 10 Version 21H1
321+
* Windows 10 Version 20H2
322+
* Windows 10 Version 2004
323+
* Windows 10 Version 1909
324+
* Windows 10 Version 1903
325+
* Windows Server 2019
326+
* Windows 10 Version 1809
327+
* Windows 10 Version 1803
328+
* Windows 10 Version 1709
329+
* Windows 10 Version 1703
330+
* Windows 10 Version 1607
331+
* Windows 10 Version 1511
332+
* Windows 10 Version 1507
267333
* Windows Server 2016
268-
* Windows 10
269334
* Windows Server 2012 R2
270335
* Windows 8.1
271336
* Windows Server 2012
@@ -275,19 +340,20 @@ def version_name(self):
275340
* Windows Server 2008
276341
* Windows Vista
277342
* Windows XP Professional x64 Edition
278-
* TODO: version (5.2) + is_workstation + bitness == 32 (don't even know if possible..)
343+
* Unknown: version (5.2) + is_workstation + bitness == 32 (don't even know if possible..)
279344
* Windows Server 2003 R2
280345
* Windows Server 2003
281346
* Windows XP
282347
* Windows 2000
283-
* "Unknow Windows <version={0} | is_workstation={1}>".format(version, is_workstation)
348+
* "Unknown Windows 10+ <versionstr={0} | is_workstation={1}>".format(self.versionstr, is_workstation)
349+
* "Unknown Windows <version={0} | is_workstation={1}>".format(version, is_workstation)
284350
285-
:type: :class:`str`
351+
:type: :class:`unicode`
286352
"""
287353
version = self.version
288354
is_workstation = self.product_type == gdef.VER_NT_WORKSTATION
289355
if version == (10, 0):
290-
return [u"Windows Server 2016", u"Windows 10"][is_workstation]
356+
return self._get_version_name_for_10_build(self.build_number, is_workstation)
291357
elif version == (6, 3):
292358
return [u"Windows Server 2012 R2", u"Windows 8.1"][is_workstation]
293359
elif version == (6, 2):
@@ -302,7 +368,7 @@ def version_name(self):
302368
if self.bitness == 64:
303369
return u"Windows XP Professional x64 Edition"
304370
else:
305-
return u"TODO: version (5.2) + is_workstation + bitness == 32"
371+
return u"Unknown: version (5.2) + is_workstation + bitness == 32"
306372
elif metric != 0:
307373
return u"Windows Server 2003 R2"
308374
else:
@@ -312,7 +378,7 @@ def version_name(self):
312378
elif version == (5, 0):
313379
return u"Windows 2000"
314380
else:
315-
return u"Unknow Windows <version={0} | is_workstation={1}>".format(version, is_workstation)
381+
return u"Unknown Windows <version={0} | is_workstation={1}>".format(version, is_workstation)
316382

317383
VERSION_MAPPER = gdef.FlagMapper(gdef.VER_NT_WORKSTATION, gdef.VER_NT_DOMAIN_CONTROLLER, gdef.VER_NT_SERVER)
318384
@utils.fixedpropety

0 commit comments

Comments
 (0)