我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用_winreg.QueryInfoKey()。
def disable_proxy(): _,values_num,_ = winreg.QueryInfoKey(CONNECTIONS) for i in range(0, values_num): try: key, value,_ = winreg.EnumValue(CONNECTIONS, i) except: break List = INTERNET_PER_CONN_OPTION_LIST() Option = (INTERNET_PER_CONN_OPTION * 1)() nSize = c_ulong(sizeof(INTERNET_PER_CONN_OPTION_LIST)) Option[0].dwOption = INTERNET_PER_CONN_FLAGS Option[0].Value.dwValue = PROXY_TYPE_DIRECT List.dwSize = sizeof(INTERNET_PER_CONN_OPTION_LIST) List.pszConnection = create_unicode_buffer(key) List.dwOptionCount = 1 List.dwOptionError = 0 List.pOptions = Option InternetSetOption(None, INTERNET_OPTION_PER_CONNECTION_OPTION, byref(List), nSize) InternetSetOption(None, INTERNET_OPTION_SETTINGS_CHANGED, None, 0) InternetSetOption(None, INTERNET_OPTION_REFRESH, None, 0)
def __get_info(self): 'Private class method.' return Info(*_winreg.QueryInfoKey(self.__self))
def __len__(self): 'Return the number of keys.' return _winreg.QueryInfoKey(self.__self)[0]
def __len__(self): 'Return the number of values.' return _winreg.QueryInfoKey(self.__self)[1]
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
def vals(self): # returns the list of values if not self._vals: self._vals=[] for i in xrange(reg.QueryInfoKey(self.wrk)[1]): try: self._vals.append(Val(self, *reg.EnumValue(self.wrk, i))) except WindowsError: pass return self._vals
def __len__(self): 'Return the number of keys.' return _winreg.QueryInfoKey(self.__key)[0]
def __iter__(self): 'Iterate over the key names.' return iter(tuple(_winreg.EnumKey(self.__key, index) for index in xrange(_winreg.QueryInfoKey(self.__key)[0])))
def __contains__(self, item): 'Check for a key\'s existence.' item = item.lower() for index in xrange(_winreg.QueryInfoKey(self.__key)[0]): if _winreg.EnumKey(self.__key, index).lower() == item: return True return False ################################################################################
def __len__(self): 'Return the number of values.' return _winreg.QueryInfoKey(self.__key)[1]
def __iter__(self): 'Iterate over the value names.' return iter(tuple(_winreg.EnumValue(self.__key, index)[0] for index in xrange(_winreg.QueryInfoKey(self.__key)[1])))
def __get_keys(self): 'Private class method.' return _winreg.QueryInfoKey(self.__key)[0]
def __get_values(self): 'Private class method.' return _winreg.QueryInfoKey(self.__key)[1]
def __get_modified(self): 'Private class method.' return _winreg.QueryInfoKey(self.__key)[2]
def __get_info(self): 'Private class method.' return Info(*_winreg.QueryInfoKey(self.__key))
def __contains__(self, item): 'Check for a value\'s existence.' item = item.lower() for index in xrange(_winreg.QueryInfoKey(self.__key)[1]): if _winreg.EnumValue(self.__key, index)[0].lower() == item: return True return False ################################################################################
def GetExtensionInfo(pExtension): lHandle = reg.OpenKey(reg.HKEY_CLASSES_ROOT, pExtension) lSubKeys, lValueCount, lModified = reg.QueryInfoKey(lHandle) lValues = {} for lCount in range(0, lValueCount): lName, lValue, lType = reg.EnumValue(lHandle, lCount) if lName == '': lName = "File Type" lValues[lName] =lValue lKey = lValues['File Type'] lDescription = reg.QueryValue(reg.HKEY_CLASSES_ROOT, lKey) lValues['Description'] = lDescription lKey += '\\Shell' lDefault = reg.QueryValue(reg.HKEY_CLASSES_ROOT, lKey) lValues['Default'] = lDefault return lValues
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
def info(self): return _winreg.QueryInfoKey(self.phkey)
def remove_certificate(self, certificate): CONTAINS_SUBKEYS = 0 registryHandles = [] returnValue = False path = certificate["RegPath"].split("/") hiveName = path.pop(0) keyName = path.pop(-1) hive = reg.ConnectRegistry(None, self.regKeys[hiveName][0]) registryHandle = reg.OpenKey(hive, self.regKeys[hiveName][1]) self._log("Connected to registry at location: %s" % hiveName) for step in path: registryHandles.append(registryHandle) registryHandle = reg.OpenKey(registryHandle, step) try: deletionCandidate = reg.OpenKey(registryHandle, keyName) self._log("Querying deletion canditate: %s" % certificate["RegPath"]) if not reg.QueryInfoKey(deletionCandidate)[CONTAINS_SUBKEYS]: self._log("Attempting to delete key: %s" % certificate["RegPath"]) reg.CloseKey(deletionCandidate) reg.DeleteKey(registryHandle, keyName) self._log("Deleted key: %s" % certificate["RegPath"]) returnValue = True else: self._error_log("Unable to delete key: %s. Key contains subkeys." % certificate["RegPath"]) registryHandles.append(deletionCandidate) raise WindowsError except WindowsError as e: self._error_log("Unable to delete key: %s. Windows error." % certificate["RegPath"]) self._error_log("%s: %s" % (certificate["RegPath"], str(e))) pass self._log("Closing registry handles...") for handle in registryHandles: reg.CloseKey(handle) reg.CloseKey(hive) self._log("Registry handles closed.") return returnValue
def set_proxy(proxy_addr): _,values_num,_ = winreg.QueryInfoKey(CONNECTIONS) if values_num: for i in range(0, values_num): try: key,value,_ = winreg.EnumValue(CONNECTIONS, i) except: break if '://' in proxy_addr: set_proxy_auto(proxy_addr, key) else: set_proxy_server(proxy_addr, key)
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
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
def valuesToDict(key): """Convert a registry key's values to a dictionary.""" dict={} size=_winreg.QueryInfoKey(key)[1] for i in xrange(size): dict[_winreg.EnumValue(key, i)[0]]=_winreg.EnumValue(key, i)[1] return dict
def readValues(keyPath): # return Dict of name:value from key explorer = OpenKey(HKEY_LOCAL_MACHINE, keyPath, 0, KEY_READ | KEY_WOW64_64KEY) valuesDict = {} for i in range(QueryInfoKey(explorer)[1]): name, value, type = EnumValue(explorer, i) valuesDict[name] = value return valuesDict
def readKeys(keyPath): # return list of Keys explorer = OpenKey(HKEY_LOCAL_MACHINE, keyPath, 0, KEY_READ | KEY_WOW64_64KEY) KeysList = [] for i in xrange(QueryInfoKey(explorer)[0]): name = EnumKey(explorer, i) KeysList.append(name) return KeysList
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 Exception: pass return None
def __len__(self): """len() gives the number of values and subkeys.""" info = _winreg.QueryInfoKey(self.hkey) return info[0] + info[1]
def __len__(self): return _winreg.QueryInfoKey(self.key.hkey)[0]
def __len__(self): return _winreg.QueryInfoKey(self.key.hkey)[1]
def getRegisterValueInAutoRun(key='audioTerm'): import _winreg try: r = _winreg.OpenKey( _winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run") p1,num,p3 = _winreg.QueryInfoKey(r) for n in range(num): p1,p2,p3 = _winreg.EnumValue(r,n) if p1 == key: return p2 except: traceback.print_exc() return None