Python winreg.QueryInfoKey() Examples
The following are 30
code examples of winreg.QueryInfoKey().
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: 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 #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: tzwin.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def valuestodict(key): """Convert a registry key's values to a dictionary.""" dict = {} size = winreg.QueryInfoKey(key)[1] for i in range(size): data = winreg.EnumValue(key, i) dict[data[0]] = data[1] return dict
Example #4
Source File: win32.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def valuestodict(key): """Convert a registry key's values to a dictionary.""" dict = {} size = winreg.QueryInfoKey(key)[1] for i in range(size): data = winreg.EnumValue(key, i) dict[data[0]] = data[1] return dict
Example #5
Source File: windows.py From mbed-os-tools with Apache License 2.0 | 5 votes |
def _iter_vals(key): """! Iterate over values of a key """ logger.debug("_iter_vals %r", key) for i in range(winreg.QueryInfoKey(key)[1]): yield winreg.EnumValue(key, i)
Example #6
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 #7
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 #8
Source File: font_manager.py From coffeegrindsize with MIT License | 5 votes |
def win32InstalledFonts(directory=None, fontext='ttf'): """ Search for fonts in the specified font directory, or use the system directories if none given. A list of TrueType font filenames are returned by default, or AFM fonts if *fontext* == 'afm'. """ import winreg if directory is None: directory = win32FontDirectory() fontext = ['.' + ext for ext in get_fontext_synonyms(fontext)] items = set() for fontdir in MSFontDirectories: try: with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, fontdir) as local: for j in range(winreg.QueryInfoKey(local)[1]): key, direc, tp = winreg.EnumValue(local, j) if not isinstance(direc, str): continue # Work around for https://bugs.python.org/issue25778, which # is fixed in Py>=3.6.1. direc = direc.split("\0", 1)[0] try: path = Path(directory, direc).resolve() except (FileNotFoundError, RuntimeError): # Don't fail with invalid entries (FileNotFoundError is # only necessary on Py3.5). continue if path.suffix.lower() in fontext: items.add(str(path)) except (OSError, MemoryError): continue return list(items)
Example #9
Source File: win32.py From bazarr with GNU General Public License v3.0 | 5 votes |
def valuestodict(key): """Convert a registry key's values to a dictionary.""" dict = {} size = winreg.QueryInfoKey(key)[1] for i in range(size): data = winreg.EnumValue(key, i) dict[data[0]] = data[1] return dict
Example #10
Source File: win32.py From komodo-wakatime with BSD 3-Clause "New" or "Revised" License | 5 votes |
def valuestodict(key): """Convert a registry key's values to a dictionary.""" dict = {} size = winreg.QueryInfoKey(key)[1] for i in range(size): data = winreg.EnumValue(key, i) dict[data[0]] = data[1] return dict
Example #11
Source File: tzwin.py From jx-sqlite with Mozilla Public License 2.0 | 5 votes |
def valuestodict(key): """Convert a registry key's values to a dictionary.""" dict = {} size = winreg.QueryInfoKey(key)[1] for i in range(size): data = winreg.EnumValue(key, i) dict[data[0]] = data[1] return dict
Example #12
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 #13
Source File: win32.py From plugin.video.iptv.recorder with GNU General Public License v3.0 | 5 votes |
def valuestodict(key): """Convert a registry key's values to a dictionary.""" dict = {} size = winreg.QueryInfoKey(key)[1] for i in range(size): data = winreg.EnumValue(key, i) dict[data[0]] = data[1] return dict
Example #14
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 #15
Source File: win32.py From xbmc-addons-chinese with GNU General Public License v2.0 | 5 votes |
def valuestodict(key): """Convert a registry key's values to a dictionary.""" dict = {} size = winreg.QueryInfoKey(key)[1] for i in range(size): data = winreg.EnumValue(key, i) dict[data[0]] = data[1] return dict
Example #16
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 #17
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 #18
Source File: regobj.py From NVDARemote with GNU General Public License v2.0 | 5 votes |
def __len__(self): """len() gives the number of values and subkeys.""" info = _winreg.QueryInfoKey(self.hkey) return info[0] + info[1]
Example #19
Source File: regobj.py From NVDARemote with GNU General Public License v2.0 | 5 votes |
def __len__(self): return _winreg.QueryInfoKey(self.key.hkey)[0]
Example #20
Source File: regobj.py From NVDARemote with GNU General Public License v2.0 | 5 votes |
def __len__(self): return _winreg.QueryInfoKey(self.key.hkey)[1]
Example #21
Source File: _win32.py From sndlatr with Apache License 2.0 | 5 votes |
def valuestodict(key): """Convert a registry key's values to a dictionary.""" dict = {} size = winreg.QueryInfoKey(key)[1] for i in range(size): data = winreg.EnumValue(key, i) dict[data[0]] = data[1] return dict
Example #22
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 #23
Source File: postinstall_simnibs.py From simnibs with GNU General Public License v3.0 | 5 votes |
def _get_win_simnibs_env_vars(): ''' 'Creates a disctionary with environment names and values ''' simnibs_env_vars = {} with winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment') as reg: _, num_values, _ = winreg.QueryInfoKey(reg) for i in range(num_values): var_name, value, _ = winreg.EnumValue(reg, i) if 'SIMNIBS' in var_name: simnibs_env_vars[var_name] = value return simnibs_env_vars
Example #24
Source File: tzwin.py From nzb-subliminal with GNU General Public License v3.0 | 5 votes |
def valuestodict(key): """Convert a registry key's values to a dictionary.""" dict = {} size = winreg.QueryInfoKey(key)[1] for i in range(size): data = winreg.EnumValue(key, i) dict[data[0]] = data[1] return dict
Example #25
Source File: font_manager.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def win32InstalledFonts(directory=None, fontext='ttf'): """ Search for fonts in the specified font directory, or use the system directories if none given. A list of TrueType font filenames are returned by default, or AFM fonts if *fontext* == 'afm'. """ import winreg if directory is None: directory = win32FontDirectory() fontext = get_fontext_synonyms(fontext) items = set() for fontdir in MSFontDirectories: try: with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, fontdir) as local: for j in range(winreg.QueryInfoKey(local)[1]): key, direc, tp = winreg.EnumValue(local, j) if not isinstance(direc, str): continue # Work around for https://bugs.python.org/issue25778, which # is fixed in Py>=3.6.1. direc = direc.split("\0", 1)[0] path = Path(directory, direc).resolve() if path.suffix.lower() in fontext: items.add(str(path)) return list(items) except (OSError, MemoryError): continue return None
Example #26
Source File: font_manager.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def win32InstalledFonts(directory=None, fontext='ttf'): """ Search for fonts in the specified font directory, or use the system directories if none given. A list of TrueType font filenames are returned by default, or AFM fonts if *fontext* == 'afm'. """ import winreg if directory is None: directory = win32FontDirectory() fontext = ['.' + ext for ext in get_fontext_synonyms(fontext)] items = set() for fontdir in MSFontDirectories: try: with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, fontdir) as local: for j in range(winreg.QueryInfoKey(local)[1]): key, direc, tp = winreg.EnumValue(local, j) if not isinstance(direc, str): continue # Work around for https://bugs.python.org/issue25778, which # is fixed in Py>=3.6.1. direc = direc.split("\0", 1)[0] try: path = Path(directory, direc).resolve() except (FileNotFoundError, RuntimeError): # Don't fail with invalid entries (FileNotFoundError is # only necessary on Py3.5). continue if path.suffix.lower() in fontext: items.add(str(path)) except (OSError, MemoryError): continue return list(items)
Example #27
Source File: _win32.py From pySINDy with MIT License | 5 votes |
def valuestodict(key): """Convert a registry key's values to a dictionary.""" dict = {} size = winreg.QueryInfoKey(key)[1] for i in range(size): data = winreg.EnumValue(key, i) dict[data[0]] = data[1] return dict
Example #28
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 #29
Source File: font_manager.py From Mastering-Elasticsearch-7.0 with MIT License | 4 votes |
def _win32RegistryFonts(reg_domain, base_dir): r""" Searches for fonts in the Windows registry. Parameters ---------- reg_domain : int The top level registry domain (e.g. HKEY_LOCAL_MACHINE). base_dir : str The path to the folder where the font files are usually located (e.g. C:\Windows\Fonts). If only the filename of the font is stored in the registry, the absolute path is built relative to this base directory. Returns ------- `set` `pathlib.Path` objects with the absolute path to the font files found. """ import winreg items = set() for reg_path in MSFontDirectories: try: with winreg.OpenKey(reg_domain, reg_path) as local: for j in range(winreg.QueryInfoKey(local)[1]): # value may contain the filename of the font or its # absolute path. key, value, tp = winreg.EnumValue(local, j) if not isinstance(value, str): continue # Work around for https://bugs.python.org/issue25778, which # is fixed in Py>=3.6.1. value = value.split("\0", 1)[0] try: # If value contains already an absolute path, then it # is not changed further. path = Path(base_dir, value).resolve() except RuntimeError: # Don't fail with invalid entries. continue items.add(path) except (OSError, MemoryError): continue return items
Example #30
Source File: _win32.py From sndlatr with Apache License 2.0 | 4 votes |
def get_localzone_name(): # Windows is special. It has unique time zone names (in several # meanings of the word) available, but unfortunately, they can be # translated to the language of the operating system, so we need to # do a backwards lookup, by going through all time zones and see which # one matches. handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) TZLOCALKEYNAME = r'SYSTEM\CurrentControlSet\Control\TimeZoneInformation' localtz = winreg.OpenKey(handle, TZLOCALKEYNAME) keyvalues = valuestodict(localtz) localtz.Close() if 'TimeZoneKeyName' in keyvalues: # Windows 7 (and Vista?) # For some reason this returns a string with loads of NUL bytes at # least on some systems. I don't know if this is a bug somewhere, I # just work around it. tzkeyname = keyvalues['TimeZoneKeyName'].split('\x00', 1)[0] else: # Windows 2000 or XP # This is the localized name: tzwin = keyvalues['StandardName'] # Open the list of timezones to look up the real name: TZKEYNAME = r'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones' tzkey = winreg.OpenKey(handle, TZKEYNAME) # Now, match this value to Time Zone information tzkeyname = None for i in range(winreg.QueryInfoKey(tzkey)[0]): subkey = winreg.EnumKey(tzkey, i) sub = winreg.OpenKey(tzkey, subkey) data = valuestodict(sub) sub.Close() if data['Std'] == tzwin: tzkeyname = subkey break tzkey.Close() handle.Close() if tzkeyname is None: raise LookupError('Can not find Windows timezone configuration') timezone = tz_names.get(tzkeyname) if timezone is None: # Nope, that didn't work. Try adding 'Standard Time', # it seems to work a lot of times: timezone = tz_names.get(tzkeyname + ' Standard Time') # Return what we have. if timezone is None: raise pytz.UnknownTimeZoneError('Can not find timezone ' + tzkeyname) return timezone