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