registry_utils.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:r2com 作者: newlog 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号