本文整理匯總了Python中winreg.QueryInfoKey方法的典型用法代碼示例。如果您正苦於以下問題:Python winreg.QueryInfoKey方法的具體用法?Python winreg.QueryInfoKey怎麽用?Python winreg.QueryInfoKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類winreg
的用法示例。
在下文中一共展示了winreg.QueryInfoKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_launcher_install_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [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
示例2: _iterate_new_uninstall_keys
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [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)
示例3: _get_win_simnibs_env_vars
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [as 別名]
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
示例4: __len__
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [as 別名]
def __len__(self):
"""len() gives the number of values and subkeys."""
info = _winreg.QueryInfoKey(self.hkey)
return info[0] + info[1]
示例5: valuestodict
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [as 別名]
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
示例6: get_cpu_info
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [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)
示例7: list
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [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
示例8: win32InstalledFonts
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [as 別名]
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
示例9: win32InstalledFonts
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [as 別名]
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)
示例10: _user_sids
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [as 別名]
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
示例11: WinSoftwareInstalled
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [as 別名]
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
示例12: _iter_keys_as_str
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [as 別名]
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)
示例13: _iter_keys
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [as 別名]
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))
示例14: _iter_vals
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [as 別名]
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)
示例15: get_localzone_name
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import QueryInfoKey [as 別名]
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