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: interface.py From XFLTReaT with MIT License | 6 votes |
def WIN_get_device_guid(self): try: regkey = registry.OpenKey(registry.HKEY_LOCAL_MACHINE, self.WINDOWS_ADAPTER_KEY) for i in xrange(10000): key_name = registry.EnumKey(regkey, i) try: regsubkey = registry.OpenKey(regkey, key_name) component_id = registry.QueryValueEx(regsubkey, "ComponentId")[0] if component_id == self.TUNTAP_COMPONENT_ID: return registry.QueryValueEx(regsubkey, 'NetCfgInstanceId')[0] except WindowsError as e: pass continue except Exception as e: pass return None return None
Example #2
Source File: test_mimetypes.py From oss-ftp with MIT License | 6 votes |
def test_non_latin_extension(self): import _winreg class MockWinreg(object): def __getattr__(self, name): if name == 'EnumKey': return lambda key, i: _winreg.EnumKey(key, i) + "\xa3" elif name == 'OpenKey': return lambda key, name: _winreg.OpenKey(key, name.rstrip("\xa3")) elif name == 'QueryValueEx': return lambda subkey, label: (u'текст/простой' , _winreg.REG_SZ) return getattr(_winreg, name) mimetypes._winreg = MockWinreg() try: # this used to throw an exception if registry contained non-Latin # characters in extensions (issue #9291) mimetypes.init() finally: mimetypes._winreg = _winreg
Example #3
Source File: DS301_index.py From CANFestivino with GNU Lesser General Public License v2.1 | 6 votes |
def get_acroversion(): " Return version of Adobe Acrobat executable or None" import _winreg adobesoft = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'Software\Adobe') for index in range(_winreg.QueryInfoKey(adobesoft)[0]): key = _winreg.EnumKey(adobesoft, index) if "acrobat" in key.lower(): acrokey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s' % key) for index in range(_winreg.QueryInfoKey(acrokey)[0]): numver = _winreg.EnumKey(acrokey, index) try: res = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s\\%s\\InstallPath' % (key, numver)) return res except: pass return None
Example #4
Source File: test_mimetypes.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_non_latin_extension(self): import _winreg class MockWinreg(object): def __getattr__(self, name): if name == 'EnumKey': return lambda key, i: _winreg.EnumKey(key, i) + "\xa3" elif name == 'OpenKey': return lambda key, name: _winreg.OpenKey(key, name.rstrip("\xa3")) elif name == 'QueryValueEx': return lambda subkey, label: (u'текст/простой' , _winreg.REG_SZ) return getattr(_winreg, name) mimetypes._winreg = MockWinreg() try: # this used to throw an exception if registry contained non-Latin # characters in extensions (issue #9291) mimetypes.init() finally: mimetypes._winreg = _winreg
Example #5
Source File: tun-ping-win.py From pyvpn with The Unlicense | 6 votes |
def get_device_guid(): with reg.OpenKey(reg.HKEY_LOCAL_MACHINE, adapter_key) as adapters: try: for i in xrange(10000): key_name = reg.EnumKey(adapters, i) with reg.OpenKey(adapters, key_name) as adapter: try: component_id = reg.QueryValueEx(adapter, 'ComponentId')[0] # print component_id # if component_id == 'tap0801': if component_id == 'tap0901': regid = reg.QueryValueEx(adapter, 'NetCfgInstanceId')[0] return 'regid:', regid except WindowsError, err: pass except WindowsError, err: pass
Example #6
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 #7
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 #8
Source File: test_mimetypes.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_non_latin_extension(self): import _winreg class MockWinreg(object): def __getattr__(self, name): if name == 'EnumKey': return lambda key, i: _winreg.EnumKey(key, i) + "\xa3" elif name == 'OpenKey': return lambda key, name: _winreg.OpenKey(key, name.rstrip("\xa3")) elif name == 'QueryValueEx': return lambda subkey, label: (u'текст/простой' , _winreg.REG_SZ) return getattr(_winreg, name) mimetypes._winreg = MockWinreg() try: # this used to throw an exception if registry contained non-Latin # characters in extensions (issue #9291) mimetypes.init() finally: mimetypes._winreg = _winreg
Example #9
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 #10
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 #11
Source File: tzwin.py From script.tv.show.next.aired with GNU General Public License v2.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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
Source File: tzwin.py From Crunchyroll-XML-Decoder with GNU General Public License v2.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: winregistry.py From cross3d with MIT License | 5 votes |
def listRegKeys(registry, key, architecture=None): import _winreg regKey = getRegKey(registry, key, architecture=architecture) ret = [] if regKey: index = 0 while True: try: ret.append(_winreg.EnumKey(regKey, index)) index += 1 except WindowsError: break return ret
Example #19
Source File: registry.py From AltFS with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_sub_keys(key): """Returns a list of all sub keys under the given registry key""" index = 0 sub_keys = [] while True: try: sub_keys.append(_winreg.EnumKey(key, index)) index += 1 except WindowsError as e: if not (hasattr(e, "winerror") and e.winerror == WIN_ERROR_NO_MORE_DATA): logger.error(e, exc_info=True) break return sub_keys
Example #20
Source File: scan_installed_apps.py From CNCGToolKit with MIT License | 5 votes |
def scan_installed_apps(): """ scan installed apps in windows system :return: """ apps_list = [] for key_root in [_winreg.HKEY_CURRENT_USER, _winreg.HKEY_LOCAL_MACHINE]: for key_path in ["SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"]: try: key = _winreg.OpenKey(key_root, key_path) # list all installed Apps i = 0 while True: app = {} sub_key_name = _winreg.EnumKey(key, i) sub_key = _winreg.OpenKey(key, sub_key_name) try: app["display_name"] = _winreg.QueryValueEx(sub_key, "DisplayName")[0] app["path"] = _winreg.QueryValueEx(sub_key, "InstallLocation")[0] apps_list.append(app) except WindowsError: pass i += 1 except WindowsError: pass return apps_list
Example #21
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 #22
Source File: registry_obj.py From Fastir_Collector with GNU General Public License v3.0 | 5 votes |
def get_sub_key(self, index): try: if self.path != "": return RegistryKey(self.hive, self.path + "\\" + EnumKey(self.key, index)) else: return RegistryKey(self.hive, EnumKey(self.key, index)) except WindowsError: return None
Example #23
Source File: list_ports_windows.py From AstroBox with GNU Affero General Public License v3.0 | 5 votes |
def filter_usb_dev_keys(base, vid, pid): vidpattern = "[0-9A-Fa-f]{4}" pidpattern = "[0-9A-Fa-f]{4}" if vid is not None: vidpattern = convert_to_16_bit_hex(vid) if pid is not None: pidpattern = convert_to_16_bit_hex(pid) pattern = re.compile("VID_(%s)&PID_(%s)" %(vidpattern, pidpattern), re.IGNORECASE) try: key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, base) except WindowsError as e: logging.getLogger('list_ports_windows').error('WindowsError: ' + e.strerror) raise VIDPIDAccessError for devnum in itertools.count(): try: devname = winreg.EnumKey(key, devnum) except EnvironmentError as e: break m = pattern.match(devname) if m is not None: yield {'key': base + devname, 'VID': m.group(1), 'PID': m.group(2)}
Example #24
Source File: registry_obj.py From Fastir_Collector with GNU General Public License v3.0 | 5 votes |
def get_sub_keys_names(self): l = [] for i in xrange(self.get_number_of_sub_keys()): l.append(EnumKey(self.key, i)) return l
Example #25
Source File: recipe-502268.py From code with MIT License | 5 votes |
def keys(self): # returns a dict of subkeys if not self._keys: self._keys={} for i in xrange(reg.QueryInfoKey(self.wrk)[0]): name=reg.EnumKey(self.wrk, i).lower() try: self._keys[name]=Key(self, name) except WindowsError: pass return self._keys
Example #26
Source File: recipe-577381.py From code with MIT License | 5 votes |
def get_keys(self): values = [] with _winreg.OpenKey(self._hive, self._key) as root_key: try: for i in range(100000): key = _winreg.EnumKey(root_key, i) if '\x00' in key: continue values.append(key) except WindowsError: pass return values
Example #27
Source File: tzwin.py From SmartAlarmClock with MIT License | 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 #28
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 #29
Source File: install.py From anima with MIT License | 5 votes |
def install_scripts(): """installs javascripts for python """ # find photoshop install dir reg_key_path = r"SOFTWARE\Adobe\Photoshop" with OpenKey(HKEY_LOCAL_MACHINE, reg_key_path) as k: version_sub_key_name = EnumKey(k, 0) version_sub_key = OpenKey(k, version_sub_key_name) install_path = QueryValue(version_sub_key, "ApplicationPath") # now copy all the files under scripts folder to # photoshop/Presets/Scripts path photoshop_scripts_path = os.path.normpath( os.path.join( install_path, 'Presets', 'Scripts' ) ) print(photoshop_scripts_path) here = os.path.dirname(__file__) scripts_folder = os.path.join(here, 'scripts') for root, dirs, files in os.walk(scripts_folder): for file_ in files: file_path = os.path.join(root, file_) shutil.copy( os.path.normpath(file_path), photoshop_scripts_path + '\\' )
Example #30
Source File: win.py From luci-py with Apache License 2.0 | 5 votes |
def get_visual_studio_versions(): """Retrieves all installed Visual Studio versions. The returned version list is sorted such that the first element is the highest version number. Returns: A list of Visual Studio version strings. """ import _winreg try: k = _winreg.OpenKey( _winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Wow6432Node\\Microsoft\\VSCommon') # pylint: disable=undefined-variable except WindowsError: return None try: versions = [] for i in range(_winreg.QueryInfoKey(k)[0]): sub_key = _winreg.EnumKey(k, i) if re.match(r'\d+\.\d+', sub_key): versions.append(sub_key) return sorted(versions, key=float, reverse=True) finally: k.Close()