Python winreg.EnumKey() Examples
The following are 30
code examples of winreg.EnumKey().
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: regobj.py From NVDARemote with GNU General Public License v2.0 | 6 votes |
def next(self): try: k = _winreg.EnumKey(self.key.hkey,self.index) except WindowsError: raise StopIteration else: self.index += 1 return Key(k,self.key)
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: reader.py From pypykatz with MIT License | 6 votes |
def enum_key(self, key_path, throw = True): if self.root is None: self.setup() #key_path = self.hive_name + '\\' + key_path key = self.find_key(key_path, throw) names = [] i = 0 while True: try: name = winreg.EnumKey(key, i) names.append(name) i+= 1 except OSError as e: if isinstance(e, WindowsError) and e.winerror == 259: break else: raise e return names
Example #4
Source File: uninstall.py From pyxll-examples with The Unlicense | 6 votes |
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 #5
Source File: reg_watcher.py From galaxy-integration-humblebundle with GNU General Public License v3.0 | 6 votes |
def _iterate_new_uninstall_keys(self): for arch_key in self._ARCH_KEYS: for hive in self._LOOKUP_REGISTRY_HIVES: with winreg.OpenKey(hive, self._UNINSTALL_LOCATION, 0, winreg.KEY_READ | arch_key) as key: subkeys = winreg.QueryInfoKey(key)[0] cached_subkeys = self.__keys_count[hive | arch_key] self.__keys_count[hive | arch_key] = subkeys if subkeys <= cached_subkeys: continue # same or lower number of installed programs since last refresh logging.info(f'New keys in registry {hive | arch_key}: {subkeys}. Reparsing.') for i in range(subkeys): subkey_name = winreg.EnumKey(key, i) if self._ignore_filter and self._ignore_filter(subkey_name): logging.debug(f'Filtred out subkey: {subkey_name}') continue with winreg.OpenKey(key, subkey_name) as subkey: yield (subkey_name, subkey)
Example #6
Source File: mimetypes.py From Imogen with MIT License | 5 votes |
def read_windows_registry(self, strict=True): """ Load the MIME types database from Windows registry. If strict is true, information will be added to list of standard types, else to the list of non-standard types. """ # Windows only if not _winreg: return def enum_types(mimedb): i = 0 while True: try: ctype = _winreg.EnumKey(mimedb, i) except OSError: break else: if '\0' not in ctype: yield ctype i += 1 with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr: for subkeyname in enum_types(hkcr): try: with _winreg.OpenKey(hkcr, subkeyname) as subkey: # Only check file extensions if not subkeyname.startswith("."): continue # raises OSError if no 'Content Type' value mimetype, datatype = _winreg.QueryValueEx( subkey, 'Content Type') if datatype != _winreg.REG_SZ: continue self.add_type(mimetype, subkeyname, strict) except OSError: continue
Example #7
Source File: tzwin.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def list(): """Return a list of all time zones known to the system.""" handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) tzkey = winreg.OpenKey(handle, TZKEYNAME) result = [winreg.EnumKey(tzkey, i) for i in range(winreg.QueryInfoKey(tzkey)[0])] tzkey.Close() handle.Close() return result
Example #8
Source File: mimetypes.py From ironpython3 with Apache License 2.0 | 5 votes |
def read_windows_registry(self, strict=True): """ Load the MIME types database from Windows registry. If strict is true, information will be added to list of standard types, else to the list of non-standard types. """ # Windows only if not _winreg: return def enum_types(mimedb): i = 0 while True: try: ctype = _winreg.EnumKey(mimedb, i) except EnvironmentError: break else: if '\0' not in ctype: yield ctype i += 1 with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr: for subkeyname in enum_types(hkcr): try: with _winreg.OpenKey(hkcr, subkeyname) as subkey: # Only check file extensions if not subkeyname.startswith("."): continue # raises EnvironmentError if no 'Content Type' value mimetype, datatype = _winreg.QueryValueEx( subkey, 'Content Type') if datatype != _winreg.REG_SZ: continue self.add_type(mimetype, subkeyname, strict) except EnvironmentError: continue
Example #9
Source File: get_applications.py From BoomER with GNU General Public License v3.0 | 5 votes |
def get_subkeys(self, key): i = 0 my_list = [] while True: try: subkey = winreg.EnumKey(key, i) my_list.append(subkey) i += 1 except WindowsError as e: break return my_list
Example #10
Source File: helper.py From skcom with MIT License | 5 votes |
def reg_find_value(key, value, root=winreg.HKEY_LOCAL_MACHINE): """ 遞迴搜尋機碼下的值, 回傳一組 tuple (所在位置, 數值) 字串資料採用局部比對, 其餘型態採用完整比對 """ i = 0 handle = winreg.OpenKey(root, key) vtype = type(value) while True: try: values = reg_list_value(key) for vname in values: # 型態不同忽略 if not isinstance(values[vname], vtype): continue leaf_node = key + ':' + vname if isinstance(value, str): # 字串採用局部比對 if value in values[vname]: return (leaf_node, values[vname]) else: # 其餘型態採用完整比對 if value == values[vname]: return (leaf_node, values[vname]) subkey = key + '\\' + winreg.EnumKey(handle, i) result = reg_find_value(subkey, value) if result[0] != '': return result i += 1 except OSError: # winreg.EnumKey(handle, i) 的 i 超出範圍 break winreg.CloseKey(handle) return ('', '')
Example #11
Source File: rpath.py From r-bridge-install with Apache License 2.0 | 5 votes |
def _user_sids(): """Map between usernames and the related SID.""" user_sids = {} root_key = winreg.HKEY_LOCAL_MACHINE reg_path = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList" try: log.info("OpenKey on {}, with READ + WOW64".format(reg_path)) sid_reg = winreg.OpenKey(root_key, reg_path, 0, READ_ACCESS) except fnf_exception as error: handle_fnf(error) if sid_reg: subkey_count = winreg.QueryInfoKey(sid_reg)[0] for pos in range(subkey_count): try: sid = winreg.EnumKey(sid_reg, pos) except: pass if sid: profile_path_key = "{}\\{}".format(reg_path, sid) try: profile_path_reg = winreg.OpenKey( root_key, profile_path_key, 0, READ_ACCESS) profile_path = winreg.QueryValueEx( profile_path_reg, "ProfileImagePath")[0] username = profile_path.split("\\")[-1] user_sids[username] = sid except: pass return user_sids
Example #12
Source File: QgsFmvInstaller.py From QGISFMV with GNU General Public License v3.0 | 5 votes |
def WinSoftwareInstalled(hive, flag): aReg = winreg.ConnectRegistry(None, hive) aKey = winreg.OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", 0, winreg.KEY_READ | flag) count_subkey = winreg.QueryInfoKey(aKey)[0] software_list = [] for i in range(count_subkey): software = {} try: asubkey_name = winreg.EnumKey(aKey, i) asubkey = winreg.OpenKey(aKey, asubkey_name) software['name'] = winreg.QueryValueEx(asubkey, "DisplayName")[0] try: software['version'] = winreg.QueryValueEx(asubkey, "DisplayVersion")[0] except EnvironmentError: software['version'] = 'undefined' try: software['publisher'] = winreg.QueryValueEx(asubkey, "Publisher")[0] except EnvironmentError: software['publisher'] = 'undefined' software_list.append(software) except EnvironmentError: continue return software_list
Example #13
Source File: tzwin.py From jx-sqlite with Mozilla Public License 2.0 | 5 votes |
def list(): """Return a list of all time zones known to the system.""" handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) tzkey = winreg.OpenKey(handle, TZKEYNAME) result = [winreg.EnumKey(tzkey, i) for i in range(winreg.QueryInfoKey(tzkey)[0])] tzkey.Close() handle.Close() return result
Example #14
Source File: mimetypes.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def read_windows_registry(self, strict=True): """ Load the MIME types database from Windows registry. If strict is true, information will be added to list of standard types, else to the list of non-standard types. """ # Windows only if not _winreg: return def enum_types(mimedb): i = 0 while True: try: ctype = _winreg.EnumKey(mimedb, i) except EnvironmentError: break else: if '\0' not in ctype: yield ctype i += 1 with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr: for subkeyname in enum_types(hkcr): try: with _winreg.OpenKey(hkcr, subkeyname) as subkey: # Only check file extensions if not subkeyname.startswith("."): continue # raises EnvironmentError if no 'Content Type' value mimetype, datatype = _winreg.QueryValueEx( subkey, 'Content Type') if datatype != _winreg.REG_SZ: continue self.add_type(mimetype, subkeyname, strict) except EnvironmentError: continue
Example #15
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 #16
Source File: mimetypes.py From odoo13-x64 with GNU General Public License v3.0 | 5 votes |
def read_windows_registry(self, strict=True): """ Load the MIME types database from Windows registry. If strict is true, information will be added to list of standard types, else to the list of non-standard types. """ # Windows only if not _winreg: return def enum_types(mimedb): i = 0 while True: try: ctype = _winreg.EnumKey(mimedb, i) except OSError: break else: if '\0' not in ctype: yield ctype i += 1 with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr: for subkeyname in enum_types(hkcr): try: with _winreg.OpenKey(hkcr, subkeyname) as subkey: # Only check file extensions if not subkeyname.startswith("."): continue # raises OSError if no 'Content Type' value mimetype, datatype = _winreg.QueryValueEx( subkey, 'Content Type') if datatype != _winreg.REG_SZ: continue self.add_type(mimetype, subkeyname, strict) except OSError: continue
Example #17
Source File: windows.py From mbed-os-tools with Apache License 2.0 | 5 votes |
def _iter_keys_as_str(key): """! Iterate over subkeys of a key returning subkey as string """ for i in range(winreg.QueryInfoKey(key)[0]): yield winreg.EnumKey(key, i)
Example #18
Source File: windows.py From mbed-os-tools with Apache License 2.0 | 5 votes |
def _iter_keys(key): """! Iterate over subkeys of a key """ for i in range(winreg.QueryInfoKey(key)[0]): yield winreg.OpenKey(key, winreg.EnumKey(key, i))
Example #19
Source File: mimetypes.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def read_windows_registry(self, strict=True): """ Load the MIME types database from Windows registry. If strict is true, information will be added to list of standard types, else to the list of non-standard types. """ # Windows only if not _winreg: return def enum_types(mimedb): i = 0 while True: try: ctype = _winreg.EnumKey(mimedb, i) except OSError: break else: if '\0' not in ctype: yield ctype i += 1 with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr: for subkeyname in enum_types(hkcr): try: with _winreg.OpenKey(hkcr, subkeyname) as subkey: # Only check file extensions if not subkeyname.startswith("."): continue # raises OSError if no 'Content Type' value mimetype, datatype = _winreg.QueryValueEx( subkey, 'Content Type') if datatype != _winreg.REG_SZ: continue self.add_type(mimetype, subkeyname, strict) except OSError: continue
Example #20
Source File: mimetypes.py From android_universal with MIT License | 5 votes |
def read_windows_registry(self, strict=True): """ Load the MIME types database from Windows registry. If strict is true, information will be added to list of standard types, else to the list of non-standard types. """ # Windows only if not _winreg: return def enum_types(mimedb): i = 0 while True: try: ctype = _winreg.EnumKey(mimedb, i) except OSError: break else: if '\0' not in ctype: yield ctype i += 1 with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr: for subkeyname in enum_types(hkcr): try: with _winreg.OpenKey(hkcr, subkeyname) as subkey: # Only check file extensions if not subkeyname.startswith("."): continue # raises OSError if no 'Content Type' value mimetype, datatype = _winreg.QueryValueEx( subkey, 'Content Type') if datatype != _winreg.REG_SZ: continue self.add_type(mimetype, subkeyname, strict) except OSError: continue
Example #21
Source File: testbuild.py From ce_tools with MIT License | 5 votes |
def check_installed_vs_versions(): """ Query the registry to find installed VS versions. Assumes that C++ support has been installed. Throws an exception if the expected version of VS is not present. :return: None """ import winreg # Open the Visual Studio registry key. reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) vskey = winreg.OpenKey(reg, r'SOFTWARE\Microsoft\VisualStudio') subkeys = [] # Read all the subkeys try: i = 0 while True: subkeys.append(winreg.EnumKey(vskey, i)) i += 1 except OSError: pass # If a subkey includes '.0' it's almost certainly a version number. I've yet to see one without that. available_versions = [version for version in subkeys if '.0' in version] if args.vcversion not in available_versions: raise OSError('Visual Studio version {} is not installed (available: {}).'.format(args.vcversion, available_versions))
Example #22
Source File: nt.py From async_dns with MIT License | 5 votes |
def get_nameservers(): ''' Get nameservers from Windows Registry. ''' nameservers = [] hlm = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) servers = _nt_read_key(hlm, r'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters') if servers is not None: nameservers.extend(servers) interfaces = winreg.OpenKey( hlm, r'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces') i = 0 while True: try: guid = winreg.EnumKey(interfaces, i) i += 1 if not _nt_is_enabled(hlm, guid): continue servers = _nt_read_key(interfaces, guid) if servers is not None: nameservers.extend(servers) except EnvironmentError: break interfaces.Close() hlm.Close() return nameservers
Example #23
Source File: mimetypes.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def read_windows_registry(self, strict=True): """ Load the MIME types database from Windows registry. If strict is true, information will be added to list of standard types, else to the list of non-standard types. """ # Windows only if not _winreg: return def enum_types(mimedb): i = 0 while True: try: ctype = _winreg.EnumKey(mimedb, i) except EnvironmentError: break else: if '\0' not in ctype: yield ctype i += 1 with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr: for subkeyname in enum_types(hkcr): try: with _winreg.OpenKey(hkcr, subkeyname) as subkey: # Only check file extensions if not subkeyname.startswith("."): continue # raises EnvironmentError if no 'Content Type' value mimetype, datatype = _winreg.QueryValueEx( subkey, 'Content Type') if datatype != _winreg.REG_SZ: continue self.add_type(mimetype, subkeyname, strict) except EnvironmentError: continue
Example #24
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 #25
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)
Example #26
Source File: _core.py From photoshop-python-api with MIT License | 5 votes |
def get_program_id(self) -> str: key = self.open_key(self.REG_PATH) return winreg.EnumKey(key, 0)
Example #27
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 #28
Source File: tzwin.py From nzb-subliminal with GNU General Public License v3.0 | 5 votes |
def list(): """Return a list of all time zones known to the system.""" handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) tzkey = winreg.OpenKey(handle, TZKEYNAME) result = [winreg.EnumKey(tzkey, i) for i in range(winreg.QueryInfoKey(tzkey)[0])] tzkey.Close() handle.Close() return result
Example #29
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 #30
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