Python winreg.KEY_WOW64_32KEY Examples

The following are 20 code examples of winreg.KEY_WOW64_32KEY(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module winreg , or try the search function .
Example #1
Source File: _core.py    From photoshop-python-api with MIT License 7 votes vote down vote up
def open_key(key):
        """Open the register key.

        Args:
            key (str): The key of register.

        Returns:
            str: The handle to the specified key.

        """
        machine_type = platform.machine()
        mappings = {"AMD64": winreg.KEY_WOW64_64KEY}
        return winreg.OpenKey(
            winreg.HKEY_LOCAL_MACHINE,
            key,
            access=winreg.KEY_READ | mappings.get(machine_type,
                                                  winreg.KEY_WOW64_32KEY),
        ) 
Example #2
Source File: animation.py    From coffeegrindsize with MIT License 6 votes vote down vote up
def _init_from_registry(cls):
        if sys.platform != 'win32' or rcParams[cls.exec_key] != 'convert':
            return
        import winreg
        for flag in (0, winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY):
            try:
                hkey = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE,
                                        r'Software\Imagemagick\Current',
                                        0, winreg.KEY_QUERY_VALUE | flag)
                binpath = winreg.QueryValueEx(hkey, 'BinPath')[0]
                winreg.CloseKey(hkey)
                break
            except Exception:
                binpath = ''
        if binpath:
            for exe in ('convert.exe', 'magick.exe'):
                path = os.path.join(binpath, exe)
                if os.path.exists(path):
                    binpath = path
                    break
            else:
                binpath = ''
        rcParams[cls.exec_key] = rcParamsDefault[cls.exec_key] = binpath 
Example #3
Source File: animation.py    From GraphicDesignPatternByPython with MIT License 6 votes vote down vote up
def _init_from_registry(cls):
        if sys.platform != 'win32' or rcParams[cls.exec_key] != 'convert':
            return
        import winreg
        for flag in (0, winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY):
            try:
                hkey = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE,
                                        r'Software\Imagemagick\Current',
                                        0, winreg.KEY_QUERY_VALUE | flag)
                binpath = winreg.QueryValueEx(hkey, 'BinPath')[0]
                winreg.CloseKey(hkey)
                break
            except Exception:
                binpath = ''
        if binpath:
            for exe in ('convert.exe', 'magick.exe'):
                path = os.path.join(binpath, exe)
                if os.path.exists(path):
                    binpath = path
                    break
            else:
                binpath = ''
        rcParams[cls.exec_key] = rcParamsDefault[cls.exec_key] = binpath 
Example #4
Source File: animation.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _init_from_registry(cls):
        if sys.platform != 'win32' or rcParams[cls.exec_key] != 'convert':
            return
        import winreg
        for flag in (0, winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY):
            try:
                hkey = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE,
                                        r'Software\Imagemagick\Current',
                                        0, winreg.KEY_QUERY_VALUE | flag)
                binpath = winreg.QueryValueEx(hkey, 'BinPath')[0]
                winreg.CloseKey(hkey)
                break
            except Exception:
                binpath = ''
        if binpath:
            for exe in ('convert.exe', 'magick.exe'):
                path = os.path.join(binpath, exe)
                if os.path.exists(path):
                    binpath = path
                    break
            else:
                binpath = ''
        rcParams[cls.exec_key] = rcParamsDefault[cls.exec_key] = binpath 
Example #5
Source File: uninstall.py    From pyxll-examples with The Unlicense 6 votes vote down vote up
def uninstall_all():
    """uninstalls PyXLL from all installed Excel versions"""
    for wow64_flags in (winreg.KEY_WOW64_64KEY, winreg.KEY_WOW64_32KEY):
        for root in _root_keys.keys():
            try:
                flags = wow64_flags | winreg.KEY_READ
                office_root = winreg.OpenKey(root, r"Software\Microsoft\Office", 0, flags)
            except WindowsError:
                continue

            # look for all installed versions of Excel and uninstall PyXLL
            i = 0
            while True:
                try:
                    subkey = winreg.EnumKey(office_root, i)
                except WindowsError:
                    break

                match = re.match("^(\d+(?:\.\d+)?)$", subkey)
                if match:
                    office_version = match.group(1)
                    uninstall(office_root, office_version, wow64_flags)
                i += 1

            winreg.CloseKey(office_root) 
Example #6
Source File: QgsFmvInstaller.py    From QGISFMV with GNU General Public License v3.0 6 votes vote down vote up
def IsLavFilters():
    ''' Check if LavFilters is present '''
    if windows:
        software_list = WinSoftwareInstalled(winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_32KEY) + WinSoftwareInstalled(winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_64KEY) + WinSoftwareInstalled(winreg.HKEY_CURRENT_USER, 0)
        if not any('LAV Filters' in software['name'] for software in software_list):
            # does not exist
            return False
    else:
        cache = apt.Cache()
        cache.open()
        try:
            #print("lav filters")
            return cache["gst123"].is_installed
        except Exception:
            # does not exist
            return False
    return True 
Example #7
Source File: _msvccompiler.py    From android_universal with MIT License 5 votes vote down vote up
def _find_vc2015():
    try:
        key = winreg.OpenKeyEx(
            winreg.HKEY_LOCAL_MACHINE,
            r"Software\Microsoft\VisualStudio\SxS\VC7",
            access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
        )
    except OSError:
        log.debug("Visual C++ is not registered")
        return None, None

    best_version = 0
    best_dir = None
    with key:
        for i in count():
            try:
                v, vc_dir, vt = winreg.EnumValue(key, i)
            except OSError:
                break
            if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
                try:
                    version = int(float(v))
                except (ValueError, TypeError):
                    continue
                if version >= 14 and version > best_version:
                    best_version, best_dir = version, vc_dir
    return best_version, best_dir 
Example #8
Source File: _msvccompiler.py    From setuptools with MIT License 5 votes vote down vote up
def _find_vc2015():
    try:
        key = winreg.OpenKeyEx(
            winreg.HKEY_LOCAL_MACHINE,
            r"Software\Microsoft\VisualStudio\SxS\VC7",
            access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
        )
    except OSError:
        log.debug("Visual C++ is not registered")
        return None, None

    best_version = 0
    best_dir = None
    with key:
        for i in count():
            try:
                v, vc_dir, vt = winreg.EnumValue(key, i)
            except OSError:
                break
            if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
                try:
                    version = int(float(v))
                except (ValueError, TypeError):
                    continue
                if version >= 14 and version > best_version:
                    best_version, best_dir = version, vc_dir
    return best_version, best_dir 
Example #9
Source File: fuse.py    From ff4d with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def Reg32GetValue(rootkey, keyname, valname):
            key, val = None, None
            try:
                key = reg.OpenKey(rootkey, keyname, 0, reg.KEY_READ | reg.KEY_WOW64_32KEY)
                val = str(reg.QueryValueEx(key, valname)[0])
            except WindowsError:
                pass
            finally:
                if key is not None:
                    reg.CloseKey(key)
            return val 
Example #10
Source File: reg_watcher.py    From galaxy-integration-humblebundle with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, ignore_filter: Optional[Callable[[str], bool]]=None):
        self._ignore_filter = ignore_filter

        if self._is_os_64bit():
            self._ARCH_KEYS = [winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY]
        else:
            self._ARCH_KEYS = [0]

        self.__uninstall_keys: Set[UninstallKey] = set()
        self.__keys_count: Dict[int, int] = {
            arch | hive : 0
            for arch in self._ARCH_KEYS
            for hive in self._LOOKUP_REGISTRY_HIVES
        } 
Example #11
Source File: uninstall.py    From pyxll-examples with The Unlicense 5 votes vote down vote up
def _get_arch(flags):
    if flags & winreg.KEY_WOW64_64KEY:
        return "64 bit"
    elif flags & winreg.KEY_WOW64_32KEY:
        return "32 bit"
    return "unknown" 
Example #12
Source File: setup.py    From miasm with GNU General Public License v2.0 5 votes vote down vote up
def win_get_llvm_reg():
    REG_PATH = "SOFTWARE\\LLVM\\LLVM"
    try:
      return winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, REG_PATH, 0, winreg.KEY_READ | winreg.KEY_WOW64_32KEY)
    except FileNotFoundError:
      pass
    return winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, REG_PATH, 0, winreg.KEY_READ) 
Example #13
Source File: _msvccompiler.py    From Imogen with MIT License 5 votes vote down vote up
def _find_vc2015():
    try:
        key = winreg.OpenKeyEx(
            winreg.HKEY_LOCAL_MACHINE,
            r"Software\Microsoft\VisualStudio\SxS\VC7",
            access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
        )
    except OSError:
        log.debug("Visual C++ is not registered")
        return None, None

    best_version = 0
    best_dir = None
    with key:
        for i in count():
            try:
                v, vc_dir, vt = winreg.EnumValue(key, i)
            except OSError:
                break
            if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
                try:
                    version = int(float(v))
                except (ValueError, TypeError):
                    continue
                if version >= 14 and version > best_version:
                    best_version, best_dir = version, vc_dir
    return best_version, best_dir 
Example #14
Source File: env.py    From teleport with Apache License 2.0 5 votes vote down vote up
def _winreg_read(self, base, path, key):
        try:
            if self.is_win_x64:
                hkey = winreg.CreateKeyEx(base, path, 0, winreg.KEY_READ | winreg.KEY_WOW64_32KEY)
            else:
                hkey = winreg.CreateKeyEx(base, path, 0, winreg.KEY_READ)

            value = winreg.QueryValueEx(hkey, key)
            return value

        except OSError:
            return None 
Example #15
Source File: env.py    From teleport with Apache License 2.0 5 votes vote down vote up
def _winreg_read(self, base, path, key):
        try:
            if self.is_win_x64:
                hkey = winreg.CreateKeyEx(base, path, 0, winreg.KEY_READ | winreg.KEY_WOW64_32KEY)
            else:
                hkey = winreg.CreateKeyEx(base, path, 0, winreg.KEY_READ)

            value = winreg.QueryValueEx(hkey, key)
            return value

        except OSError:
            return None 
Example #16
Source File: main.py    From DecompilerMC with MIT License 4 votes vote down vote up
def checkjava():
    """Check for java and setup the proper directory if needed"""
    results = []
    if sys.platform.startswith('win'):
        if not results:
            import winreg

            for flag in [winreg.KEY_WOW64_64KEY, winreg.KEY_WOW64_32KEY]:
                try:
                    k = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'Software\JavaSoft\Java Development Kit', 0, winreg.KEY_READ | flag)
                    version, _ = winreg.QueryValueEx(k, 'CurrentVersion')
                    k.Close()
                    k = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'Software\JavaSoft\Java Development Kit\%s' % version, 0, winreg.KEY_READ | flag)
                    path, _ = winreg.QueryValueEx(k, 'JavaHome')
                    k.Close()
                    path = os.path.join(str(path), 'bin')
                    subprocess.run(['"%s"' % os.path.join(path, 'java'), ' -version'], stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT, check=True)
                    results.append(path)
                except (CalledProcessError, OSError):
                    pass
        if not results:
            try:
                subprocess.run(['java', '-version'], stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT, check=True)
                results.append('')
            except (CalledProcessError, OSError):
                pass
        if not results and 'ProgramW6432' in os.environ:
            results.extend(which('java.exe', os.environ['ProgramW6432']))
        if not results and 'ProgramFiles' in os.environ:
            results.extend(which('java.exe', os.environ['ProgramFiles']))
        if not results and 'ProgramFiles(x86)' in os.environ:
            results.extend(which('java.exe', os.environ['ProgramFiles(x86)']))
    elif sys.platform.startswith('linux') or sys.platform.startswith('darwin'):
        if not results:
            try:
                subprocess.run(['java', '-version'], stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT, check=True)
                results.append('')
            except (CalledProcessError, OSError):
                pass
        if not results:
            results.extend(which('java', path='/usr/bin'))
        if not results:
            results.extend(which('java', path='/usr/local/bin'))
        if not results:
            results.extend(which('java', path='/opt'))
    if not results:
        print('Java JDK is not installed ! Please install java JDK from http://java.oracle.com or OpenJDK')
        input("Aborting, press anything to exit")
        sys.exit(1) 
Example #17
Source File: _msvccompiler.py    From Fluid-Designer with GNU General Public License v3.0 4 votes vote down vote up
def _find_vcvarsall(plat_spec):
    try:
        key = winreg.OpenKeyEx(
            winreg.HKEY_LOCAL_MACHINE,
            r"Software\Microsoft\VisualStudio\SxS\VC7",
            access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
        )
    except OSError:
        log.debug("Visual C++ is not registered")
        return None, None

    with key:
        best_version = 0
        best_dir = None
        for i in count():
            try:
                v, vc_dir, vt = winreg.EnumValue(key, i)
            except OSError:
                break
            if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
                try:
                    version = int(float(v))
                except (ValueError, TypeError):
                    continue
                if version >= 14 and version > best_version:
                    best_version, best_dir = version, vc_dir
        if not best_version:
            log.debug("No suitable Visual C++ version found")
            return None, None

        vcvarsall = os.path.join(best_dir, "vcvarsall.bat")
        if not os.path.isfile(vcvarsall):
            log.debug("%s cannot be found", vcvarsall)
            return None, None

        vcruntime = None
        vcruntime_spec = _VCVARS_PLAT_TO_VCRUNTIME_REDIST.get(plat_spec)
        if vcruntime_spec:
            vcruntime = os.path.join(best_dir,
                vcruntime_spec.format(best_version))
            if not os.path.isfile(vcruntime):
                log.debug("%s cannot be found", vcruntime)
                vcruntime = None

        return vcvarsall, vcruntime 
Example #18
Source File: prepare.py    From tqdb with MIT License 4 votes vote down vote up
def tqdb_prepare():
    # Open the TQAE key and grab the install location:
    try:
        tqae_key = winreg.OpenKey(
            winreg.HKEY_LOCAL_MACHINE, LOOKUP_KEY, 0, winreg.KEY_READ)
    except FileNotFoundError:
        import platform

        bitness = platform.architecture()[0]
        if bitness == '32bit':
            other_view_flag = winreg.KEY_WOW64_64KEY
        elif bitness == '64bit':
            other_view_flag = winreg.KEY_WOW64_32KEY
        else:
            raise RuntimeError("Platform architecture not recognized: " +
                               bitness)

        try:
            tqae_key = winreg.OpenKey(
                winreg.HKEY_LOCAL_MACHINE, LOOKUP_KEY,
                access = winreg.KEY_READ | other_view_flag)
        except WindowsError as err:
            raise RuntimeError('Could not find installation directory for '
                               'Titan Quest.') from err

    try:
        install = winreg.QueryValueEx(tqae_key, 'InstallLocation')[0]
    except WindowsError as err:
        raise RuntimeError('Could not find installation directory for Titan '
                           'Quest.') from err

    logging.info("Found TQ installation directory: " + install)

    # Create the required directories if necessary
    for d in DIRECTORIES:
        Path(d).mkdir(parents=True, exist_ok=True)

    # Run the extraction commands:
    tool = Path(install, 'ArchiveTool.exe')
    for c in COMMANDS:
        input_file = Path(install, c[0])
        subprocess.run([
            # ArchiveTool.exe in the TQ Install directory
            str(tool),
            # Resource ARC file in the TQ Install directory
            str(input_file),
            # Extract flag for the ArchiveTool executable
            '-extract',
            # Output directory (local data/ dir)
            str(Path(c[1]).absolute()),
        ]) 
Example #19
Source File: _msvccompiler.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 4 votes vote down vote up
def _find_vcvarsall(plat_spec):
    try:
        key = winreg.OpenKeyEx(
            winreg.HKEY_LOCAL_MACHINE,
            r"Software\Microsoft\VisualStudio\SxS\VC7",
            access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
        )
    except OSError:
        log.debug("Visual C++ is not registered")
        return None, None

    with key:
        best_version = 0
        best_dir = None
        for i in count():
            try:
                v, vc_dir, vt = winreg.EnumValue(key, i)
            except OSError:
                break
            if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
                try:
                    version = int(float(v))
                except (ValueError, TypeError):
                    continue
                if version >= 14 and version > best_version:
                    best_version, best_dir = version, vc_dir
        if not best_version:
            log.debug("No suitable Visual C++ version found")
            return None, None

        vcvarsall = os.path.join(best_dir, "vcvarsall.bat")
        if not os.path.isfile(vcvarsall):
            log.debug("%s cannot be found", vcvarsall)
            return None, None

        vcruntime = None
        vcruntime_spec = _VCVARS_PLAT_TO_VCRUNTIME_REDIST.get(plat_spec)
        if vcruntime_spec:
            vcruntime = os.path.join(best_dir,
                vcruntime_spec.format(best_version))
            if not os.path.isfile(vcruntime):
                log.debug("%s cannot be found", vcruntime)
                vcruntime = None

        return vcvarsall, vcruntime 
Example #20
Source File: win_app_paths.py    From textext with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def get_non_syspath_dirs():
    """Returns a list containing the directories of the applications which are not found in the system path"""

    # Try standard registry and the 32bit as well as 64bit mapping of it
    for access_right in [_wr.KEY_READ, _wr.KEY_READ | _wr.KEY_WOW64_32KEY, _wr.KEY_READ | _wr.KEY_WOW64_64KEY]:
        # Global instalations put their keys in HKLM (HKEY_LOCAL_MACHINE), user installations
        # put their keys in HKCU (HKEY_CURRENT_USER)
        for hkey in [_wr.HKEY_LOCAL_MACHINE, _wr.HKEY_CURRENT_USER]:
            try:
                key = _wr.OpenKey(hkey, INKSCAPE_REG_KEY, 0, access_right)
                try:
                    # Inkscape stores its installation location in a Standard key -> ""
                    value, _ = _wr.QueryValueEx(key, "")
                    _wr.CloseKey(key)
                    dirname = _os.path.join(value, "bin")
                    return [dirname] if _os.path.isdir(dirname) else []
                except WindowsError:
                    _wr.CloseKey(key)
            except WindowsError:
                pass

    # Last chance: Guess at the two common locations
    for dirname in ["C:\\Program Files\\Inkscape\\bin", "C:\\Program Files (x86)\\Inkscape\\bin"]:
        if _os.path.isfile(_os.path.join(dirname, "inkscape.exe")):
            return [dirname]

    # Give up
    return []