Skip to content

Commit

Permalink
pythongh-114107: test.pythoninfo logs Windows Developer Mode
Browse files Browse the repository at this point in the history
Also, don't skip the whole collect_windows() if ctypes is missing.
  • Loading branch information
vstinner committed Jan 16, 2024
1 parent a482bc6 commit f44a442
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions Lib/test/pythoninfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,26 +865,25 @@ def collect_subprocess(info_add):


def collect_windows(info_add):
# windows.RtlAreLongPathsEnabled: RtlAreLongPathsEnabled()
try:
import ctypes
if not hasattr(ctypes, 'WinDLL'):
raise ImportError
except ImportError:
return

if not hasattr(ctypes, 'WinDLL'):
return

ntdll = ctypes.WinDLL('ntdll')
BOOLEAN = ctypes.c_ubyte

try:
RtlAreLongPathsEnabled = ntdll.RtlAreLongPathsEnabled
except AttributeError:
res = '<function not available>'
pass
else:
RtlAreLongPathsEnabled.restype = BOOLEAN
RtlAreLongPathsEnabled.argtypes = ()
res = bool(RtlAreLongPathsEnabled())
info_add('windows.RtlAreLongPathsEnabled', res)
ntdll = ctypes.WinDLL('ntdll')
BOOLEAN = ctypes.c_ubyte
try:
RtlAreLongPathsEnabled = ntdll.RtlAreLongPathsEnabled
except AttributeError:
res = '<function not available>'
else:
RtlAreLongPathsEnabled.restype = BOOLEAN
RtlAreLongPathsEnabled.argtypes = ()
res = bool(RtlAreLongPathsEnabled())
info_add('windows.RtlAreLongPathsEnabled', res)

try:
import _winapi
Expand All @@ -893,6 +892,7 @@ def collect_windows(info_add):
except (ImportError, AttributeError):
pass

# windows.version_caption: "wmic os get Caption,Version /value" command
import subprocess
try:
# When wmic.exe output is redirected to a pipe,
Expand All @@ -919,6 +919,7 @@ def collect_windows(info_add):
if line:
info_add('windows.version', line)

# windows.ver: "ver" command
try:
proc = subprocess.Popen(["ver"], shell=True,
stdout=subprocess.PIPE,
Expand All @@ -937,6 +938,22 @@ def collect_windows(info_add):
if line:
info_add('windows.ver', line)

# windows.developer_mode: get AllowDevelopmentWithoutDevLicense registry
import winreg
try:
key = winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock")
subkey = "AllowDevelopmentWithoutDevLicense"
try:
value, value_type = winreg.QueryValueEx(key, subkey)
finally:
winreg.CloseKey(key)
except OSError:
pass
else:
info_add('windows.developer_mode', "enabled" if value else "disabled")


def collect_fips(info_add):
try:
Expand Down

0 comments on commit f44a442

Please sign in to comment.