def __get_key_values(root_key, key):
"""This method gets the values and subkeys from the given key under the
root key.
Args:
root_key (str): The root key as abbreviated string.
Valid values: [hklm, hkcr, hkcu, hku, hkpd, hkcc].
key (str): The subkey starting from the root key.
e.g.: SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\interfaces
Returns:
list. It returns the retrieved values and subkeys
or an empty list if data could not be retrieved.
"""
values = []
i = 0
try:
hkey = _winreg.OpenKey(root_key, key, 0, _winreg.KEY_READ)
except WindowsError as e:
logging.error('Key ({0}) could not be opened: {1}'.format(key, e))
return values
while True:
try:
value = _winreg.EnumKey(hkey, i)
values.append(value)
i += 1
except WindowsError:
logging.info('No more values. Total values: {0}'.format(i))
if hkey:
_winreg.CloseKey(hkey)
break # no more values
return values
评论列表
文章目录