(info_add)
| 876 | |
| 877 | |
| 878 | def collect_windows(info_add): |
| 879 | if sys.platform != "win32": |
| 880 | # Code specific to Windows |
| 881 | return |
| 882 | |
| 883 | # windows.RtlAreLongPathsEnabled: RtlAreLongPathsEnabled() |
| 884 | # windows.is_admin: IsUserAnAdmin() |
| 885 | try: |
| 886 | import ctypes |
| 887 | if not hasattr(ctypes, 'WinDLL'): |
| 888 | raise ImportError |
| 889 | except ImportError: |
| 890 | pass |
| 891 | else: |
| 892 | ntdll = ctypes.WinDLL('ntdll') |
| 893 | BOOLEAN = ctypes.c_ubyte |
| 894 | try: |
| 895 | RtlAreLongPathsEnabled = ntdll.RtlAreLongPathsEnabled |
| 896 | except AttributeError: |
| 897 | res = '<function not available>' |
| 898 | else: |
| 899 | RtlAreLongPathsEnabled.restype = BOOLEAN |
| 900 | RtlAreLongPathsEnabled.argtypes = () |
| 901 | res = bool(RtlAreLongPathsEnabled()) |
| 902 | info_add('windows.RtlAreLongPathsEnabled', res) |
| 903 | |
| 904 | shell32 = ctypes.windll.shell32 |
| 905 | IsUserAnAdmin = shell32.IsUserAnAdmin |
| 906 | IsUserAnAdmin.restype = BOOLEAN |
| 907 | IsUserAnAdmin.argtypes = () |
| 908 | info_add('windows.is_admin', IsUserAnAdmin()) |
| 909 | |
| 910 | try: |
| 911 | import _winapi |
| 912 | dll_path = _winapi.GetModuleFileName(sys.dllhandle) |
| 913 | info_add('windows.dll_path', dll_path) |
| 914 | except (ImportError, AttributeError): |
| 915 | pass |
| 916 | |
| 917 | # windows.version_caption: "wmic os get Caption,Version /value" command |
| 918 | import subprocess |
| 919 | try: |
| 920 | # When wmic.exe output is redirected to a pipe, |
| 921 | # it uses the OEM code page |
| 922 | proc = subprocess.Popen(["wmic", "os", "get", "Caption,Version", "/value"], |
| 923 | stdout=subprocess.PIPE, |
| 924 | stderr=subprocess.PIPE, |
| 925 | encoding="oem", |
| 926 | text=True) |
| 927 | output, stderr = proc.communicate() |
| 928 | if proc.returncode: |
| 929 | output = "" |
| 930 | except OSError: |
| 931 | pass |
| 932 | else: |
| 933 | for line in output.splitlines(): |
| 934 | line = line.strip() |
| 935 | if line.startswith('Caption='): |
nothing calls this directly
no test coverage detected