From 766f1f5e0a0378c14c1f177eed043150cdc5774f Mon Sep 17 00:00:00 2001 From: hakril Date: Fri, 10 Jan 2025 11:01:05 +0100 Subject: [PATCH] Improving system.version_number for 10+ by taking build number into account --- tests/test_system.py | 2 +- windows/winobject/system.py | 41 ++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/tests/test_system.py b/tests/test_system.py index c0466e9..09bb502 100644 --- a/tests/test_system.py +++ b/tests/test_system.py @@ -13,6 +13,7 @@ class TestSystemWithCheckGarbage(object): def test_version_name(self): assert is_unicode(windows.system.version_name) + assert u"unknown" not in windows.system.version_name.lower() def test_version_product_type(self): assert windows.system.product_type @@ -26,7 +27,6 @@ class TestSystemWithCheckGarbage(object): def test_version_versionstr(self): assert is_unicode(windows.system.windir) - def test_computer_name(self): computer_name = windows.system.computer_name assert computer_name diff --git a/windows/winobject/system.py b/windows/winobject/system.py index c23afd3..fa3abc2 100644 --- a/windows/winobject/system.py +++ b/windows/winobject/system.py @@ -260,6 +260,40 @@ class System(object): result = tuple(result_tup[:2]) return result + + + WINDOWS_10_BUILD_NUMBER_VERSION = { + # (build_number, is_workstation): "version_name" + (10240, True): "Windows 10 Version 1507", + (10586, True): "Windows 10 Version 1511", + (14393, True): "Windows 10 Version 1607", + (15063, True): "Windows 10 Version 1703", + (16299, True): "Windows 10 Version 1709", + (17134, True): "Windows 10 Version 1803", + (17763, True): "Windows 10 Version 1809", + (18362, True): "Windows 10 Version 1903", + (18363, True): "Windows 10 Version 1909", + (19041, True): "Windows 10 Version 2004", + (19042, True): "Windows 10 Version 20H2", + (19043, True): "Windows 10 Version 21H1", + (19044, True): "Windows 10 Version 21H2", + (19045, True): "Windows 10 Version 22H2", + (22000, True): "Windows 11 Version 21H2", + (22621, True): "Windows 11 Version 22H2", + (22631, True): "Windows 11 Version 23H2", + (26100, True): "Windows 11 Version 24H2", + + (14393, False): "Windows Server 2016", + (17763, False): "Windows Server 2019", + (20348, False): "Windows Server 2022", + } + + def _get_version_name_for_10_build(self, build_number, is_workstation): + try: + return self.WINDOWS_10_BUILD_NUMBER_VERSION[(build_number, is_workstation)] + except KeyError as e: + return u"Unknown Windows 10+ ".format(self.versionstr, is_workstation) + @utils.fixedpropety def version_name(self): """The name of the system version, values are: @@ -280,14 +314,15 @@ class System(object): * Windows Server 2003 * Windows XP * Windows 2000 - * "Unknow Windows ".format(version, is_workstation) + * "Unknown Windows ".format(version, is_workstation) :type: :class:`str` """ version = self.version is_workstation = self.product_type == gdef.VER_NT_WORKSTATION if version == (10, 0): - return [u"Windows Server 2016", u"Windows 10"][is_workstation] + return self._get_version_name_for_10_build(self.build_number, is_workstation) + # return [u"Windows Server 2016", u"Windows 10"][is_workstation] elif version == (6, 3): return [u"Windows Server 2012 R2", u"Windows 8.1"][is_workstation] elif version == (6, 2): @@ -312,7 +347,7 @@ class System(object): elif version == (5, 0): return u"Windows 2000" else: - return u"Unknow Windows ".format(version, is_workstation) + return u"Unknown Windows ".format(version, is_workstation) VERSION_MAPPER = gdef.FlagMapper(gdef.VER_NT_WORKSTATION, gdef.VER_NT_DOMAIN_CONTROLLER, gdef.VER_NT_SERVER) @utils.fixedpropety