Package platformids :: Package dist :: Package nt :: Module windows_kernel32dll

Source Code for Module platformids.dist.nt.windows_kernel32dll

  1  # -*- coding: utf-8 -*- 
  2  """MS-Windows releases for the WindowsNT family. 
  3   
  4  .. note:: 
  5   
  6     **ATTENTION**: The ostype == RTE_NT uses for *dist* and *distrel* it's own non-default  
  7     encoding, while the scheme follows the default record layout, see ':ref:`Windows NT <enumWINNT>`'. 
  8  """ 
  9  from __future__ import absolute_import 
 10   
 11  import sys 
 12   
 13  from platformids import RTE_NT, RTE_WIN, RTE_WINDOWS, \ 
 14      rte2num, num2rte, num2pretty 
 15   
 16  __author__ = 'Arno-Can Uestuensoez' 
 17  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
 18  __copyright__ = "Copyright (C) 2010-2018 Arno-Can Uestuensoez" \ 
 19                  " @Ingenieurbuero Arno-Can Uestuensoez" 
 20  __version__ = '0.1.2' 
 21  __uuid__ = "7add5ded-c39b-4b6e-8c87-1b3a1c150ee9" 
 22   
 23  __docformat__ = "restructuredtext en" 
 24   
 25   
 26  # 
 27  # Microsoft: OSVERSIONINFOEXA.wProductType 
 28  # 
 29  VER_NT_WORKSTATION       = 0x0000001  #: see wProductType 
 30  VER_NT_DOMAIN_CONTROLLER = 0x0000002  #: see wProductType 
 31  VER_NT_SERVER            = 0x0000003  #: see wProductType 
 32   
 33  VER_NT_IOT               = 0x0000004  #: non standard enum 
 34   
 35  # 
 36  # platform specific adapters: win/nt and cygwin 
 37  # 
 38  if sys.platform in ('win32',): 
 39      import ctypes 
 40      kernel32 = ctypes.windll.kernel32  # @UndefinedVariable 
 41   
 42  elif sys.platform in ('cygwin',): 
 43      import ctypes  # @Reimport 
 44      kernel32 = ctypes.CDLL('kernel32.dll') 
 45   
 46   
47 -def get_win32_OSVersionInfo():
48 try: 49 class OSVersionInfo(ctypes.Structure): 50 _fields_ = [ 51 ("dwOSVersionInfoSize" , ctypes.c_int), # DWORD 52 ("dwMajorVersion" , ctypes.c_int), # DWORD 53 ("dwMinorVersion" , ctypes.c_int), # DWORD 54 ("dwBuildNumber" , ctypes.c_int), # DWORD 55 ("dwPlatformId" , ctypes.c_int), # DWORD 56 ("szCSDVersion" , ctypes.c_char * 128), # CHAR 57 ] 58 59 _GetVersionEx = getattr( ctypes.windll.kernel32 , "GetVersionExA") # @UndefinedVariable 60 version = OSVersionInfo() 61 version.dwOSVersionInfoSize = ctypes.sizeof(OSVersionInfo) 62 _GetVersionEx( ctypes.byref(version) ) 63 return version 64 65 except: 66 return 67
68 -def get_win32_OSVersionInfoExa():
69 """Retuns a structure OSVERSIONINFOEXA, which contains the value 70 for wProductType. 71 """ 72 try: 73 class OSVersionInfoExa(ctypes.Structure): 74 _fields_ = [ 75 ("dwOSVersionInfoSize" , ctypes.c_int), # DWORD 76 ("dwMajorVersion" , ctypes.c_int), # DWORD 77 ("dwMinorVersion" , ctypes.c_int), # DWORD 78 ("dwBuildNumber" , ctypes.c_int), # DWORD 79 ("dwPlatformId" , ctypes.c_int), # DWORD 80 ("szCSDVersion" , ctypes.c_char * 128), # CHAR 81 82 ("wServicePackMajor" , ctypes.c_int16), # WORD 83 ("wServicePackMinor" , ctypes.c_int16), # WORD 84 ("wSuiteMask" , ctypes.c_int16), # WORD 85 ("wProductType" , ctypes.c_int8), # BYTE 86 # wProductType - one of: 87 # - VER_NT_DOMAIN_CONTROLLER 88 # - VER_NT_SERVER 89 # - VER_NT_WORKSTATION 90 # 91 ("wReserved" , ctypes.c_int8), # BYTE 92 93 ];
94 95 _GetVersionExa = getattr( kernel32 , "GetVersionExA") 96 version = OSVersionInfoExa() 97 version.dwOSVersionInfoSize = ctypes.sizeof(OSVersionInfoExa) 98 _GetVersionExa( ctypes.byref(version) ) 99 return version 100 101 except: 102 return 103
104 -def get_win32_OSProductInfo():
105 106 # BOOL WINAPI GetProductInfo( 107 # _In_ DWORD dwOSMajorVersion, 108 # _In_ DWORD dwOSMinorVersion, 109 # _In_ DWORD dwSpMajorVersion, 110 # _In_ DWORD dwSpMinorVersion, 111 # _Out_ PDWORD pdwReturnedProductType 112 # ); 113 114 try: 115 class OSProdInfo(ctypes.Structure): 116 _fields_ = [ 117 ("pdwReturnedProductType" , ctypes.c_int), # PDWORD 118 ]; 119 120 _GetProductInfo = getattr( kernel32 , "GetProductInfo") 121 ptype = OSProdInfo() 122 ptype.dwOSVersionInfoSize = ctypes.sizeof(OSProdInfo) 123 124 osver = get_win32_OSVersionInfoExa() 125 _GetProductInfo( 126 ctypes.c_int(osver.dwMajorVersion), 127 ctypes.c_int(osver.dwMinorVersion), 128 ctypes.c_int(osver.wServicePackMajor), 129 ctypes.c_int(osver.wServicePackMinor), 130 ctypes.byref(ptype) 131 ) 132 return ptype 133 134 except: 135 return 136 154 155
156 -def get_win32_IsWindowsXPSP1OrGreater():
157 158 try: 159 # BOOL WINAPI IsWindowsXPSP1OrGreater( 160 # ); 161 162 class OSProdInfo(ctypes.Structure): 163 _fields_ = [ 164 ("pdwReturnedProductType" , ctypes.c_int), # PDWORD 165 ]; 166 167 _IsWindowsXPSP1OrGreater = getattr( kernel32 , "IsWindowsXPSP1OrGreater") 168 return _IsWindowsXPSP1OrGreater() 169 170 except: 171 return 172