def windows_variant(): """Determine Windows variant Return vista_plus, x64 """ from win32api import GetVersionEx from win32con import VER_PLATFORM_WIN32_NT import winreg vista_plus = x64 = False maj, _minor, _buildno, plat, _csd = GetVersionEx() if plat == VER_PLATFORM_WIN32_NT: vista_plus = maj > 5 if vista_plus: # Must be done the hard way, because the Python runtime lies to us. # This does *not* work: # return os.environ['PROCESSOR_ARCHITECTURE'] == 'AMD64' # because the Python runtime returns 'X86' even on an x64 system! key = winreg.OpenKey( winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ) for n in range(winreg.QueryInfoKey(key)[1]): name, value, _val_type = winreg.EnumValue(key, n) if name == "PROCESSOR_ARCHITECTURE": x64 = value.upper() == "AMD64" break winreg.CloseKey(key) return vista_plus, x64
def determine_win_version(): ver_info = GetVersionEx(1) is_home = bool(ver_info[7] & VER_SUITE_PERSONAL) if ver_info[:2] == (6, 0): return "Vista", is_home elif ver_info[0] >= 6: return "Later than Vista", is_home else: return "Something else", is_home
def getOSVersion(self): """ This function returns a Version-ready tuple. For use with the Version object, use extended call syntax: v = Version(*getOSVersion()) v.full() """ if os.name == 'posix': sysname, nodename, version, build, arch = os.uname() name = "%s (%s)" % (sysname, arch) major, minor, micro = getVersionTupleFromString(version) comment = ' '.join(os.uname()) elif os.name == 'nt': from win32api import GetVersionEx major, minor, micro, platformID, additional = GetVersionEx() name = 'Windows %s (%s)' % (os.name.upper(), additional) comment = '' else: raise VersionNotSupported return Version(name, major, minor, micro, 0, comment)
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 functions only works if Mark Hammond's win32 package is installed and 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. """ # Import the needed APIs try: import win32api except ImportError: return release, version, csd, ptype from win32api import RegQueryValueEx, RegOpenKeyEx, RegCloseKey, GetVersionEx from win32con import HKEY_LOCAL_MACHINE,VER_PLATFORM_WIN32_NT,\ VER_PLATFORM_WIN32_WINDOWS # 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' else: release = '98' 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: release = '2000' 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
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 VER_NT_SERVER = 3 REG_SZ = 1 # Find out the registry key and some general version infos winver = GetVersionEx() maj, min, buildno, plat, csd = winver version = '%i.%i.%i' % (maj, min, buildno & 0xFFFF) if hasattr(winver, "service_pack"): if winver.service_pack != "": csd = 'SP%s' % winver.service_pack_major else: 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 hasattr(winver, "product_type"): product_type = winver.product_type else: product_type = VER_NT_WORKSTATION # Without an OSVERSIONINFOEX capable sys.getwindowsversion(), # or help from the registry, we cannot properly identify # non-workstation versions. try: key = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey) name, type = RegQueryValueEx(key, "ProductName") # Discard any type that isn't REG_SZ if type == REG_SZ and name.find("Server") != -1: product_type = VER_NT_SERVER except WindowsError: # Use default of VER_NT_WORKSTATION pass if min == 0: if product_type == VER_NT_WORKSTATION: release = 'Vista' else: release = '2008Server' elif min == 1: if product_type == VER_NT_WORKSTATION: release = '7' else: release = '2008ServerR2' 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
'Unable to start the configuration program of Natlink/Unimacro/Vocola:' ) print('the python module natlinkconfigfunctions.py gives an error.') print() print('Please report this error message to the Natlink developers,') print('preferably to [email protected]') print() import traceback traceback.print_exc() # time.sleep(30) sys.exit() try: # see natlinkstatus.py for windows versions (getWindowsVersion) wversion = GetVersionEx() if wversion[3] == 2 and wversion[0] >= 6: # Vista and later, run as administrator, so elevated mode: openpar = "runas" else: openpar = "open" pathToPythonW = os.path.join(sys.prefix, "pythonw.exe") if not os.path.isfile(pathToPythonW): print("cannot find the Pythonw exectutable: %s" % pathToPythonW) # time.sleep(30) sys.exit() configPath = os.path.join(os.path.dirname(__file__), "configurenatlink.pyw") if not os.path.isfile(configPath):
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. """ 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: try: sys.getwindowsversion except AttributeError: return (release, version, csd, ptype) 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 VER_NT_SERVER = 3 REG_SZ = 1 winver = GetVersionEx() maj, min, buildno, plat, csd = winver version = '%i.%i.%i' % (maj, min, buildno & 65535) if hasattr(winver, 'service_pack'): if winver.service_pack != '': csd = 'SP%s' % winver.service_pack_major elif csd[:13] == 'Service Pack ': csd = 'SP' + csd[13:] if plat == VER_PLATFORM_WIN32_WINDOWS: regkey = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion' 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 hasattr(winver, 'product_type'): product_type = winver.product_type else: product_type = VER_NT_WORKSTATION try: key = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey) name, type = RegQueryValueEx(key, 'ProductName') if type == REG_SZ and name.find('Server') != -1: product_type = VER_NT_SERVER except WindowsError: pass if min == 0: if product_type == VER_NT_WORKSTATION: release = 'Vista' else: release = '2008Server' elif min == 1: if product_type == VER_NT_WORKSTATION: release = '7' else: release = '2008ServerR2' else: release = 'post2008Server' else: if not release: release = '%i.%i' % (maj, min) return (release, version, csd, ptype) try: keyCurVer = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey) RegQueryValueEx(keyCurVer, 'SystemRoot') except: return (release, version, csd, ptype) build = _win32_getvalue(keyCurVer, 'CurrentBuildNumber', ('', 1))[0] ptype = _win32_getvalue(keyCurVer, 'CurrentType', (ptype, 1))[0] version = _norm_version(version, build) RegCloseKey(keyCurVer) return (release, version, csd, ptype)
def win32_ver(release='', version='', csd='', ptype=''): return ('Unknown', '', '', '') 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: try: sys.getwindowsversion except AttributeError: return (release, version, csd, ptype) 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 VER_NT_SERVER = 3 REG_SZ = 1 winver = GetVersionEx() (maj, min, buildno, plat, csd) = winver version = '%i.%i.%i' % (maj, min, buildno & 65535) if hasattr(winver, 'service_pack'): if winver.service_pack != '': csd = 'SP%s' % winver.service_pack_major elif csd[:13] == 'Service Pack ': csd = 'SP' + csd[13:] if plat == VER_PLATFORM_WIN32_WINDOWS: regkey = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion' if maj == 4: if min == 0: release = '95' elif min == 10: release = '98' elif min == 90: release = 'Me' else: release = 'postMe' if maj == 5: release = '2000' 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' if maj == 6: if hasattr(winver, 'product_type'): product_type = winver.product_type else: product_type = VER_NT_WORKSTATION try: key = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey) (name, type) = RegQueryValueEx(key, 'ProductName') while type == REG_SZ and name.find('Server') != -1: product_type = VER_NT_SERVER except WindowsError: pass if min == 0: if product_type == VER_NT_WORKSTATION: release = 'Vista' else: release = '2008Server' if min == 1: if product_type == VER_NT_WORKSTATION: release = '7' else: release = '2008ServerR2' if min == 2: if product_type == VER_NT_WORKSTATION: release = '8' else: release = '2012Server' release = 'post2012Server' else: release = 'post2012Server' elif min == 2: if product_type == VER_NT_WORKSTATION: release = '8' else: release = '2012Server' release = 'post2012Server' else: release = 'post2012Server' elif min == 1: if product_type == VER_NT_WORKSTATION: release = '7' else: release = '2008ServerR2' if min == 2: if product_type == VER_NT_WORKSTATION: release = '8' else: release = '2012Server' release = 'post2012Server' else: release = 'post2012Server' elif min == 2: if product_type == VER_NT_WORKSTATION: release = '8' else: release = '2012Server' release = 'post2012Server' else: release = 'post2012Server' elif maj == 6: if hasattr(winver, 'product_type'): product_type = winver.product_type else: product_type = VER_NT_WORKSTATION try: key = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey) (name, type) = RegQueryValueEx(key, 'ProductName') while type == REG_SZ and name.find('Server') != -1: product_type = VER_NT_SERVER except WindowsError: pass if min == 0: if product_type == VER_NT_WORKSTATION: release = 'Vista' else: release = '2008Server' if min == 1: if product_type == VER_NT_WORKSTATION: release = '7' else: release = '2008ServerR2' if min == 2: if product_type == VER_NT_WORKSTATION: release = '8' else: release = '2012Server' release = 'post2012Server' else: release = 'post2012Server' elif min == 2: if product_type == VER_NT_WORKSTATION: release = '8' else: release = '2012Server' release = 'post2012Server' else: release = 'post2012Server' elif min == 1: if product_type == VER_NT_WORKSTATION: release = '7' else: release = '2008ServerR2' if min == 2: if product_type == VER_NT_WORKSTATION: release = '8' else: release = '2012Server' release = 'post2012Server' else: release = 'post2012Server' elif min == 2: if product_type == VER_NT_WORKSTATION: release = '8' else: release = '2012Server' release = 'post2012Server' else: release = 'post2012Server' else: if not release: release = '%i.%i' % (maj, min) return (release, version, csd, ptype) try: keyCurVer = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey) RegQueryValueEx(keyCurVer, 'SystemRoot') except: return (release, version, csd, ptype) build = _win32_getvalue(keyCurVer, 'CurrentBuildNumber', ('', 1))[0] ptype = _win32_getvalue(keyCurVer, 'CurrentType', (ptype, 1))[0] version = _norm_version(version, build) RegCloseKey(keyCurVer) return (release, version, csd, ptype)
def main(): #we have to add the current path and its parent to the search path. current_dir = pathlib.WindowsPath(__file__) parent_dir = current_dir.parent for p in (current_dir, parent_dir): sys.path.append(str(p)) # print('Starting start_configurenatlink.py,') print( 'Try to run configurenatlink.py, the Natlink Config GUI, in Elevated mode...' ) print() if sys.version.find("64 bit") >= 0: print('''=============================================\n You run this module from a 64 bit version of Python.\n Natlink cannot run with this version, please be sure to \n install a 32 bit version of python, and run from there.\n See https://qh.antenna.nl/unimacro/installation/problemswithinstallation.html\n =============================================''') time.sleep(30) sys.exit() try: import wx from win32api import ShellExecute, GetVersionEx except (Exception, e): print( f'''Unable to run the GUI configuration program of Natlink/Unimacro/Vocola\n because a module was not found. An error occurred during import. This is probably due to a missing or incorrect prequisite.\n Please run 'pip install -r requirements.txt in {thisDir}\n More information https://qh.antenna.nl/unimacro/installation/problemswithinstallation.html\n\n Exception Details:\n{e}''') time.sleep(30) sys.exit() try: import natlinkconfigfunctions except ImportError: print( '''Unable to start the configuration program of Natlink/Unimacro/Vocola:\n the python module natlinkconfigfunctions.py gives an error.\n Please report this error message to the Natlink developers,\n preferably to [email protected]\n''') import traceback traceback.print_exc() # time.sleep(30) sys.exit() try: # see natlinkstatus.py for windows versions (getWindowsVersion) wversion = GetVersionEx() if wversion[3] == 2 and wversion[0] >= 6: # Vista and later, run as administrator, so elevated mode: openpar = "runas" else: openpar = "open" #python and pythonw.exe may be in a scripts directory in virtualenvs. #to find the path of the python executable, pathToPythonExecutables = "\\".join(sys.executable.split('\\')[0:-1]) pathToPythonW = f"{pathToPythonExecutables}\\pythonw.exe" if not os.path.isfile(pathToPythonW): print("cannot find the Pythonw exectutable: %s" % pathToPythonW) # time.sleep(30) sys.exit() configPath = os.path.join(os.path.dirname(__file__), "configurenatlink.pyw") if not os.path.isfile(configPath): print( "cannot find the Natlink/Unimacro/Vocola configuration program: %s" % configPath) # time.sleep(30) sys.exit() #print('run with "%s": %s'% (openpar, configPath) #print('sys.version: ', sys.version #time.sleep(5) ShellExecute(0, openpar, pathToPythonW, configPath, "", 1) import traceback traceback.print_exc() except: import traceback traceback.print_exc() time.sleep(60)