Пример #1
0
def GetSubKeys(keypath, ignore_errors=False):
    '''Find keys under given registry key.'''
    keytype, keyname = _SplitKey(keypath)
    lines = []
    keytype = getattr(_winreg, keytype)
    reg = _registry.ConnectRegistry(keytype)
    try:
        handle = _registry.OpenKeyEx(reg, keyname, KEY_ENUMERATE_SUB_KEYS)
    except WindowsError:
        if ignore_errors:
            return lines
        else:
            raise

    try:
        newlines = _EnumItem(_registry.EnumKeyEx, handle)
    except WindowsError:
        _registry.CloseKey(handle)
        if ignore_errors:
            return lines
        else:
            raise

    lines.extend(newlines)
    _registry.CloseKey(handle)
    return lines
Пример #2
0
def GetKeyValues(keypath, ignore_errors=False):
    '''Get (valuename, value, valuetype)-tuples from a given registry key.'''
    keytype, keyname = _SplitKey(keypath)
    lines = []
    # Get values from current key-path
    keytype = getattr(_winreg, keytype)
    reg = _registry.ConnectRegistry(keytype)
    try:
        handle = _registry.OpenKeyEx(reg, keyname, _winreg.KEY_QUERY_VALUE)
    except WindowsError:
        if ignore_errors:
            return lines
        else:
            raise

    try:
        newlines = _EnumItem(_registry.EnumValue, handle)
    except WindowsError:
        _registry.CloseKey(handle)
        if ignore_errors:
            return lines
        else:
            raise

    lines.extend(newlines)
    _registry.CloseKey(handle)
    lines.sort()
    return lines
Пример #3
0
def DeleteValue(keypath, valuename):
    '''Delete a registry value.'''
    keytype, keyname = _SplitKey(keypath)
    key = getattr(_winreg, keytype)
    reg = _registry.ConnectRegistry(key)
    handle = _registry.OpenKeyEx(reg, keyname, _winreg.KEY_SET_VALUE)
    _registry.DeleteValue(handle, valuename)
    _registry.CloseKey(handle)
Пример #4
0
def GetValue(keypath, valuename):
    '''Return (registry, registry type)-tuple.'''
    keytype, keyname = _SplitKey(keypath)
    key = getattr(_winreg, keytype)
    reg = _registry.ConnectRegistry(key)
    handle = _registry.OpenKeyEx(reg, keyname, _winreg.KEY_QUERY_VALUE)
    value, valuetype = _registry.QueryValueEx(handle, valuename)
    _registry.CloseKey(handle)
    return value, valuetype
Пример #5
0
def QueryInfoKey(keypath):
    '''Query information about a registry key.'''
    keytype, keyname = _SplitKey(keypath)
    keytype = getattr(_winreg, keytype)
    reg = _registry.ConnectRegistry(keytype)
    handle = _registry.OpenKeyEx(reg, keyname, _winreg.KEY_QUERY_VALUE)
    info = _registry.QueryInfoKey(handle)
    _registry.CloseKey(handle)
    return (info[0], info[3], info[7])
Пример #6
0
def DeleteKey(keypath):
    '''Remove a key from the registry.'''
    keypath, subkey = keypath.rsplit('\\', 1)
    keytype, keyname = _SplitKey(keypath)
    key = getattr(_winreg, keytype)
    reg = _registry.ConnectRegistry(key)
    handle = _registry.OpenKeyEx(reg, keyname, _winreg.KEY_CREATE_SUB_KEY)
    _registry.DeleteKey(handle, subkey)
    _registry.CloseKey(handle)
Пример #7
0
def SetValue(keypath, valuename, value, valuetype=None):
    '''Set registry value.'''
    keytype, keyname = _SplitKey(keypath)
    key = getattr(_winreg, keytype)
    if valuetype is None:
        valuetype = _GuessValueType(value)
    elif isinstance(valuetype, types.StringTypes):
        if valuetype == 'REG_QWORD':
            valuetype = 11
        else:
            valuetype = getattr(_winreg, valuetype)
    reg = _registry.ConnectRegistry(key)
    handle = _registry.OpenKeyEx(reg, keyname, _winreg.KEY_SET_VALUE)
    _registry.SetValueEx(handle, valuename, valuetype, value)
    _registry.CloseKey(handle)