mirror of https://github.com/python/cpython.git
gh-114107: test.pythoninfo logs Windows Developer Mode (#114121)
Also, don't skip the whole collect_windows() if ctypes is missing. Log also ctypes.windll.shell32.IsUserAnAdmin().
This commit is contained in:
parent
867f59f234
commit
c77f552ec0
|
@ -865,26 +865,36 @@ def collect_subprocess(info_add):
|
||||||
|
|
||||||
|
|
||||||
def collect_windows(info_add):
|
def collect_windows(info_add):
|
||||||
|
if sys.platform != "win32":
|
||||||
|
# Code specific to Windows
|
||||||
|
return
|
||||||
|
|
||||||
|
# windows.RtlAreLongPathsEnabled: RtlAreLongPathsEnabled()
|
||||||
|
# windows.is_admin: IsUserAnAdmin()
|
||||||
try:
|
try:
|
||||||
import ctypes
|
import ctypes
|
||||||
|
if not hasattr(ctypes, 'WinDLL'):
|
||||||
|
raise ImportError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return
|
pass
|
||||||
|
|
||||||
if not hasattr(ctypes, 'WinDLL'):
|
|
||||||
return
|
|
||||||
|
|
||||||
ntdll = ctypes.WinDLL('ntdll')
|
|
||||||
BOOLEAN = ctypes.c_ubyte
|
|
||||||
|
|
||||||
try:
|
|
||||||
RtlAreLongPathsEnabled = ntdll.RtlAreLongPathsEnabled
|
|
||||||
except AttributeError:
|
|
||||||
res = '<function not available>'
|
|
||||||
else:
|
else:
|
||||||
RtlAreLongPathsEnabled.restype = BOOLEAN
|
ntdll = ctypes.WinDLL('ntdll')
|
||||||
RtlAreLongPathsEnabled.argtypes = ()
|
BOOLEAN = ctypes.c_ubyte
|
||||||
res = bool(RtlAreLongPathsEnabled())
|
try:
|
||||||
info_add('windows.RtlAreLongPathsEnabled', res)
|
RtlAreLongPathsEnabled = ntdll.RtlAreLongPathsEnabled
|
||||||
|
except AttributeError:
|
||||||
|
res = '<function not available>'
|
||||||
|
else:
|
||||||
|
RtlAreLongPathsEnabled.restype = BOOLEAN
|
||||||
|
RtlAreLongPathsEnabled.argtypes = ()
|
||||||
|
res = bool(RtlAreLongPathsEnabled())
|
||||||
|
info_add('windows.RtlAreLongPathsEnabled', res)
|
||||||
|
|
||||||
|
shell32 = ctypes.windll.shell32
|
||||||
|
IsUserAnAdmin = shell32.IsUserAnAdmin
|
||||||
|
IsUserAnAdmin.restype = BOOLEAN
|
||||||
|
IsUserAnAdmin.argtypes = ()
|
||||||
|
info_add('windows.is_admin', IsUserAnAdmin())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import _winapi
|
import _winapi
|
||||||
|
@ -893,6 +903,7 @@ def collect_windows(info_add):
|
||||||
except (ImportError, AttributeError):
|
except (ImportError, AttributeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# windows.version_caption: "wmic os get Caption,Version /value" command
|
||||||
import subprocess
|
import subprocess
|
||||||
try:
|
try:
|
||||||
# When wmic.exe output is redirected to a pipe,
|
# When wmic.exe output is redirected to a pipe,
|
||||||
|
@ -919,6 +930,7 @@ def collect_windows(info_add):
|
||||||
if line:
|
if line:
|
||||||
info_add('windows.version', line)
|
info_add('windows.version', line)
|
||||||
|
|
||||||
|
# windows.ver: "ver" command
|
||||||
try:
|
try:
|
||||||
proc = subprocess.Popen(["ver"], shell=True,
|
proc = subprocess.Popen(["ver"], shell=True,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
|
@ -937,6 +949,22 @@ def collect_windows(info_add):
|
||||||
if line:
|
if line:
|
||||||
info_add('windows.ver', 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):
|
def collect_fips(info_add):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue