本文整理汇总了Python中_winreg.QueryInfoKey方法的典型用法代码示例。如果您正苦于以下问题:Python _winreg.QueryInfoKey方法的具体用法?Python _winreg.QueryInfoKey怎么用?Python _winreg.QueryInfoKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_winreg
的用法示例。
在下文中一共展示了_winreg.QueryInfoKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: win32_reg_read
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import QueryInfoKey [as 别名]
def win32_reg_read (self, keyname, path):
try:
import _winreg
mode = _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY
key = _winreg.OpenKey(keyname, path, 0, mode)
count = _winreg.QueryInfoKey(key)[0]
except:
return None
data = {}
for i in range(count):
try:
name, value, tt = _winreg.EnumValue(key, i)
except OSError as e:
break
data[name] = (tt, value)
return data
示例2: listRegKeyValues
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import QueryInfoKey [as 别名]
def listRegKeyValues(registry, key, architecture=None):
""" Returns a list of child keys and their values as tuples.
Each tuple contains 3 items.
- A string that identifies the value name
- An object that holds the value data, and whose type depends on the underlying registry type
- An integer that identifies the type of the value data (see table in docs for _winreg.SetValueEx)
Args:
registry (str): The registry to look in. 'HKEY_LOCAL_MACHINE' for example
key (str): The key to open. r'Software\Autodesk\Softimage\InstallPaths' for example
architecture (int | None): 32 or 64 bit. If None use system default. Defaults to None
Returns:
List of tuples
"""
import _winreg
regKey = getRegKey(registry, key, architecture=architecture)
ret = []
if regKey:
subKeys, valueCount, modified = _winreg.QueryInfoKey(regKey)
for index in range(valueCount):
ret.append(_winreg.EnumValue(regKey, index))
return ret
示例3: __init__
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import QueryInfoKey [as 别名]
def __init__(self):
self.hkey={}
for key in (k for k in dir(reg) if k.startswith('HKEY_')):
try:
chk = reg.ConnectRegistry(None, getattr(reg, key))
inf = reg.QueryInfoKey(chk)
reg.CloseKey(chk)
except WindowsError: pass # some keys may appear in _winreg but can't be reached
else:
hk = Hkey(key)
try:
chk=hk.keys
except WindowsError: pass # some keys can be accessed but not enumerated
else: # some keys work fine ...
name=key[5:].lower()
self.hkey[name]=hk # for iterating
setattr(self, name, hk) # for easy access
示例4: get_reboot_required
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import QueryInfoKey [as 别名]
def get_reboot_required():
"""Returns True if the system should be rebooted to apply updates.
This is not guaranteed to notice all conditions that could require reboot.
"""
# Based on https://stackoverflow.com/a/45717438
k = None
import _winreg
try:
k = _winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE,
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\'
'Auto Update\\RebootRequired')
_, num_values, _ = _winreg.QueryInfoKey(k)
return num_values > 0
except WindowsError: # pylint: disable=undefined-variable
# This error very likely means the RebootRequired key does not exist,
# meaning reboot is not required.
return False
finally:
if k:
k.Close()
示例5: get_acroversion
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import QueryInfoKey [as 别名]
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
示例6: __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]
示例7: 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
示例8: 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
示例9: 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
示例10: 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)
示例11: keys
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import QueryInfoKey [as 别名]
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
示例12: vals
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import QueryInfoKey [as 别名]
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
示例13: __len__
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import QueryInfoKey [as 别名]
def __len__(self):
"value is approximate since .keys() drops non-string types"
with _winreg.OpenKey(self._hive, self._key) as k:
num_subkeys, num_values, t = _winreg.QueryInfoKey(k)
return num_values
示例14: _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
示例15: get_visual_studio_versions
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import QueryInfoKey [as 别名]
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()