(version, csd, ptype)
| 386 | return None |
| 387 | |
| 388 | def _win32_ver(version, csd, ptype): |
| 389 | # Try using WMI first, as this is the canonical source of data |
| 390 | try: |
| 391 | (version, product_type, ptype, spmajor, spminor) = _wmi_query( |
| 392 | 'OS', |
| 393 | 'Version', |
| 394 | 'ProductType', |
| 395 | 'BuildType', |
| 396 | 'ServicePackMajorVersion', |
| 397 | 'ServicePackMinorVersion', |
| 398 | ) |
| 399 | is_client = (int(product_type) == 1) |
| 400 | if spminor and spminor != '0': |
| 401 | csd = f'SP{spmajor}.{spminor}' |
| 402 | else: |
| 403 | csd = f'SP{spmajor}' |
| 404 | return version, csd, ptype, is_client |
| 405 | except OSError: |
| 406 | pass |
| 407 | |
| 408 | # Fall back to a combination of sys.getwindowsversion and "ver" |
| 409 | try: |
| 410 | from sys import getwindowsversion |
| 411 | except ImportError: |
| 412 | return version, csd, ptype, True |
| 413 | |
| 414 | winver = getwindowsversion() |
| 415 | is_client = (getattr(winver, 'product_type', 1) == 1) |
| 416 | try: |
| 417 | version = _syscmd_ver()[2] |
| 418 | major, minor, build = map(int, version.split('.')) |
| 419 | except ValueError: |
| 420 | major, minor, build = winver.platform_version or winver[:3] |
| 421 | version = '{0}.{1}.{2}'.format(major, minor, build) |
| 422 | |
| 423 | # getwindowsversion() reflect the compatibility mode Python is |
| 424 | # running under, and so the service pack value is only going to be |
| 425 | # valid if the versions match. |
| 426 | if winver[:2] == (major, minor): |
| 427 | try: |
| 428 | csd = 'SP{}'.format(winver.service_pack_major) |
| 429 | except AttributeError: |
| 430 | if csd[:13] == 'Service Pack ': |
| 431 | csd = 'SP' + csd[13:] |
| 432 | |
| 433 | try: |
| 434 | import winreg |
| 435 | except ImportError: |
| 436 | pass |
| 437 | else: |
| 438 | try: |
| 439 | cvkey = r'SOFTWARE\Microsoft\Windows NT\CurrentVersion' |
| 440 | with winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE, cvkey) as key: |
| 441 | ptype = winreg.QueryValueEx(key, 'CurrentType')[0] |
| 442 | except OSError: |
| 443 | pass |
| 444 | |
| 445 | return version, csd, ptype, is_client |
no test coverage detected