@@ -864,26 +864,36 @@ def collect_subprocess(info_add):
864864
865865
866866def collect_windows (info_add ):
867- try :
868- import ctypes
869- except ImportError :
870- return
871-
872- if not hasattr (ctypes , 'WinDLL' ):
867+ if sys .platform != "win32" :
868+ # Code specific to Windows
873869 return
874870
875- ntdll = ctypes .WinDLL ('ntdll' )
876- BOOLEAN = ctypes .c_ubyte
877-
871+ # windows.RtlAreLongPathsEnabled: RtlAreLongPathsEnabled()
872+ # windows.is_admin: IsUserAnAdmin()
878873 try :
879- RtlAreLongPathsEnabled = ntdll .RtlAreLongPathsEnabled
880- except AttributeError :
881- res = '<function not available>'
874+ import ctypes
875+ if not hasattr (ctypes , 'WinDLL' ):
876+ raise ImportError
877+ except ImportError :
878+ pass
882879 else :
883- RtlAreLongPathsEnabled .restype = BOOLEAN
884- RtlAreLongPathsEnabled .argtypes = ()
885- res = bool (RtlAreLongPathsEnabled ())
886- info_add ('windows.RtlAreLongPathsEnabled' , res )
880+ ntdll = ctypes .WinDLL ('ntdll' )
881+ BOOLEAN = ctypes .c_ubyte
882+ try :
883+ RtlAreLongPathsEnabled = ntdll .RtlAreLongPathsEnabled
884+ except AttributeError :
885+ res = '<function not available>'
886+ else :
887+ RtlAreLongPathsEnabled .restype = BOOLEAN
888+ RtlAreLongPathsEnabled .argtypes = ()
889+ res = bool (RtlAreLongPathsEnabled ())
890+ info_add ('windows.RtlAreLongPathsEnabled' , res )
891+
892+ shell32 = ctypes .windll .shell32
893+ IsUserAnAdmin = shell32 .IsUserAnAdmin
894+ IsUserAnAdmin .restype = BOOLEAN
895+ IsUserAnAdmin .argtypes = ()
896+ info_add ('windows.is_admin' , IsUserAnAdmin ())
887897
888898 try :
889899 import _winapi
@@ -892,6 +902,7 @@ def collect_windows(info_add):
892902 except (ImportError , AttributeError ):
893903 pass
894904
905+ # windows.version_caption: "wmic os get Caption,Version /value" command
895906 import subprocess
896907 try :
897908 # When wmic.exe output is redirected to a pipe,
@@ -918,6 +929,7 @@ def collect_windows(info_add):
918929 if line :
919930 info_add ('windows.version' , line )
920931
932+ # windows.ver: "ver" command
921933 try :
922934 proc = subprocess .Popen (["ver" ], shell = True ,
923935 stdout = subprocess .PIPE ,
@@ -936,6 +948,22 @@ def collect_windows(info_add):
936948 if line :
937949 info_add ('windows.ver' , line )
938950
951+ # windows.developer_mode: get AllowDevelopmentWithoutDevLicense registry
952+ import winreg
953+ try :
954+ key = winreg .OpenKey (
955+ winreg .HKEY_LOCAL_MACHINE ,
956+ r"SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" )
957+ subkey = "AllowDevelopmentWithoutDevLicense"
958+ try :
959+ value , value_type = winreg .QueryValueEx (key , subkey )
960+ finally :
961+ winreg .CloseKey (key )
962+ except OSError :
963+ pass
964+ else :
965+ info_add ('windows.developer_mode' , "enabled" if value else "disabled" )
966+
939967
940968def collect_fips (info_add ):
941969 try :
0 commit comments