本文整理匯總了Python中winreg.EnumKey方法的典型用法代碼示例。如果您正苦於以下問題:Python winreg.EnumKey方法的具體用法?Python winreg.EnumKey怎麽用?Python winreg.EnumKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類winreg
的用法示例。
在下文中一共展示了winreg.EnumKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: uninstall_all
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
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)
示例2: _get_launcher_install_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
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
示例3: enum_key
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
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
示例4: _iterate_new_uninstall_keys
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
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)
示例5: next
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
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)
示例6: get_nameservers
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
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
示例7: __iter__
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
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)
示例8: _get_sid_from_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
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
示例9: get_network_card_info
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
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
示例10: get_cpu_info
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
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)
示例11: list
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
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
示例12: get_program_id
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
def get_program_id(self) -> str:
key = self.open_key(self.REG_PATH)
return winreg.EnumKey(key, 0)
示例13: read_windows_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
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
示例14: read_windows_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
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
示例15: get_subkeys
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import EnumKey [as 別名]
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