parameters: (release='',version='',csd='',ptype='')
return_statement: return release,version,csd,ptype
docstring: Get additional version information from the Windows Registry
          and return a tuple (version,csd,ptype) referring to version
          number, CSD level and OS type (multi/single
          processor).
  
          As a hint: ptype returns 'Uniprocessor Free' on single
          processor NT machines and 'Multiprocessor Free' on multi
          processor machines. The 'Free' refers to the OS version being
          free of debugging code. It could also state 'Checked' which
          means the OS version uses debugging code, i.e. code that
          checks arguments, ranges, etc. (Thomas Heller).
  
          Note: this function works best with Mark Hammond's win32
          package installed, but also on Python 2.3 and later. It
          obviously only runs on Win32 compatible platforms.
docstring_summary: Get additional version information from the Windows Registry
          and return a tuple (version,csd,ptype) referring to version
          number, CSD level and OS type (multi/single
          processor).
docstring_tokens: Get additional version information from the Windows Registry and return a tuple ( version csd ptype ) referring to version number CSD level and OS type ( multi / single processor ) .
function: def win32_ver(release='',version='',csd='',ptype=''):
  
      """ Get additional version information from the Windows Registry
          and return a tuple (version,csd,ptype) referring to version
          number, CSD level and OS type (multi/single
          processor).
  
          As a hint: ptype returns 'Uniprocessor Free' on single
          processor NT machines and 'Multiprocessor Free' on multi
          processor machines. The 'Free' refers to the OS version being
          free of debugging code. It could also state 'Checked' which
          means the OS version uses debugging code, i.e. code that
          checks arguments, ranges, etc. (Thomas Heller).
  
          Note: this function works best with Mark Hammond's win32
          package installed, but also on Python 2.3 and later. It
          obviously only runs on Win32 compatible platforms.
  
      """
      # XXX Is there any way to find out the processor type on WinXX ?
      # XXX Is win32 available on Windows CE ?
      #
      # Adapted from code posted by Karl Putland to comp.lang.python.
      #
      # The mappings between reg. values and release names can be found
      # here: http://msdn.microsoft.com/library/en-us/sysinfo/base/osversioninfo_str.asp
  
      # Import the needed APIs
      try:
          import win32api
          from win32api import RegQueryValueEx, RegOpenKeyEx, \
               RegCloseKey, GetVersionEx
          from win32con import HKEY_LOCAL_MACHINE, VER_PLATFORM_WIN32_NT, \
               VER_PLATFORM_WIN32_WINDOWS, VER_NT_WORKSTATION
      except ImportError:
          # Emulate the win32api module using Python APIs
          try:
              sys.getwindowsversion
          except AttributeError:
              # No emulation possible, so return the defaults...
              return release,version,csd,ptype
          else:
              # Emulation using _winreg (added in Python 2.0) and
              # sys.getwindowsversion() (added in Python 2.3)
              import _winreg
              GetVersionEx = sys.getwindowsversion
              RegQueryValueEx = _winreg.QueryValueEx
              RegOpenKeyEx = _winreg.OpenKeyEx
              RegCloseKey = _winreg.CloseKey
              HKEY_LOCAL_MACHINE = _winreg.HKEY_LOCAL_MACHINE
              VER_PLATFORM_WIN32_WINDOWS = 1
              VER_PLATFORM_WIN32_NT = 2
              VER_NT_WORKSTATION = 1
  
      # Find out the registry key and some general version infos
      maj,min,buildno,plat,csd = GetVersionEx()
      version = '%i.%i.%i' % (maj,min,buildno & 0xFFFF)
      if csd[:13] == 'Service Pack ':
          csd = 'SP' + csd[13:]
      if plat == VER_PLATFORM_WIN32_WINDOWS:
          regkey = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion'
          # Try to guess the release name
          if maj == 4:
              if min == 0:
                  release = '95'
              elif min == 10:
                  release = '98'
              elif min == 90:
                  release = 'Me'
              else:
                  release = 'postMe'
          elif maj == 5:
              release = '2000'
      elif plat == VER_PLATFORM_WIN32_NT:
          regkey = 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion'
          if maj <= 4:
              release = 'NT'
          elif maj == 5:
              if min == 0:
                  release = '2000'
              elif min == 1:
                  release = 'XP'
              elif min == 2:
                  release = '2003Server'
              else:
                  release = 'post2003'
          elif maj == 6:
              if min == 0:
                  # Per http://msdn2.microsoft.com/en-us/library/ms724429.aspx
                  try:
                      productType = GetVersionEx(1)[8]
                  except TypeError:
                      # sys.getwindowsversion() doesn't take any arguments, so
                      # we cannot detect 2008 Server that way.
                      # XXX Add some other means of detecting 2008 Server ?!
                      release = 'Vista'
                  else:
                      if productType == VER_NT_WORKSTATION:
                          release = 'Vista'
                      else:
                          release = '2008Server'
              else:
                  release = 'post2008Server'
      else:
          if not release:
              # E.g. Win3.1 with win32s
              release = '%i.%i' % (maj,min)
          return release,version,csd,ptype
  
      # Open the registry key
      try:
          keyCurVer = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey)
          # Get a value to make sure the key exists...
          RegQueryValueEx(keyCurVer, 'SystemRoot')
      except:
          return release,version,csd,ptype
  
      # Parse values
      #subversion = _win32_getvalue(keyCurVer,
      #                            'SubVersionNumber',
      #                            ('',1))[0]
      #if subversion:
      #   release = release + subversion # 95a, 95b, etc.
      build = _win32_getvalue(keyCurVer,
                              'CurrentBuildNumber',
                              ('',1))[0]
      ptype = _win32_getvalue(keyCurVer,
                             'CurrentType',
                             (ptype,1))[0]
  
      # Normalize version
      version = _norm_version(version,build)
  
      # Close key
      RegCloseKey(keyCurVer)
      return release,version,csd,ptype
function_tokens: def win32_ver ( release = '' , version = '' , csd = '' , ptype = '' ) : # XXX Is there any way to find out the processor type on WinXX ? # XXX Is win32 available on Windows CE ? # # Adapted from code posted by Karl Putland to comp.lang.python. # # The mappings between reg. values and release names can be found # here: http://msdn.microsoft.com/library/en-us/sysinfo/base/osversioninfo_str.asp # Import the needed APIs try : import win32api from win32api import RegQueryValueEx , RegOpenKeyEx , RegCloseKey , GetVersionEx from win32con import HKEY_LOCAL_MACHINE , VER_PLATFORM_WIN32_NT , VER_PLATFORM_WIN32_WINDOWS , VER_NT_WORKSTATION except ImportError : # Emulate the win32api module using Python APIs try : sys . getwindowsversion except AttributeError : # No emulation possible, so return the defaults... return release , version , csd , ptype else : # Emulation using _winreg (added in Python 2.0) and # sys.getwindowsversion() (added in Python 2.3) import _winreg GetVersionEx = sys . getwindowsversion RegQueryValueEx = _winreg . QueryValueEx RegOpenKeyEx = _winreg . OpenKeyEx RegCloseKey = _winreg . CloseKey HKEY_LOCAL_MACHINE = _winreg . HKEY_LOCAL_MACHINE VER_PLATFORM_WIN32_WINDOWS = 1 VER_PLATFORM_WIN32_NT = 2 VER_NT_WORKSTATION = 1 # Find out the registry key and some general version infos maj , min , buildno , plat , csd = GetVersionEx ( ) version = '%i.%i.%i' % ( maj , min , buildno & 0xFFFF ) if csd [ : 13 ] == 'Service Pack ' : csd = 'SP' + csd [ 13 : ] if plat == VER_PLATFORM_WIN32_WINDOWS : regkey = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion' # Try to guess the release name if maj == 4 : if min == 0 : release = '95' elif min == 10 : release = '98' elif min == 90 : release = 'Me' else : release = 'postMe' elif maj == 5 : release = '2000' elif plat == VER_PLATFORM_WIN32_NT : regkey = 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion' if maj <= 4 : release = 'NT' elif maj == 5 : if min == 0 : release = '2000' elif min == 1 : release = 'XP' elif min == 2 : release = '2003Server' else : release = 'post2003' elif maj == 6 : if min == 0 : # Per http://msdn2.microsoft.com/en-us/library/ms724429.aspx try : productType = GetVersionEx ( 1 ) [ 8 ] except TypeError : # sys.getwindowsversion() doesn't take any arguments, so # we cannot detect 2008 Server that way. # XXX Add some other means of detecting 2008 Server ?! release = 'Vista' else : if productType == VER_NT_WORKSTATION : release = 'Vista' else : release = '2008Server' else : release = 'post2008Server' else : if not release : # E.g. Win3.1 with win32s release = '%i.%i' % ( maj , min ) return release , version , csd , ptype # Open the registry key try : keyCurVer = RegOpenKeyEx ( HKEY_LOCAL_MACHINE , regkey ) # Get a value to make sure the key exists... RegQueryValueEx ( keyCurVer , 'SystemRoot' ) except : return release , version , csd , ptype # Parse values #subversion = _win32_getvalue(keyCurVer, #                            'SubVersionNumber', #                            ('',1))[0] #if subversion: #   release = release + subversion # 95a, 95b, etc. build = _win32_getvalue ( keyCurVer , 'CurrentBuildNumber' , ( '' , 1 ) ) [ 0 ] ptype = _win32_getvalue ( keyCurVer , 'CurrentType' , ( ptype , 1 ) ) [ 0 ] # Normalize version version = _norm_version ( version , build ) # Close key RegCloseKey ( keyCurVer ) return release , version , csd , ptype