# Function Reference

# _WinAPI_RegDeleteKey

Deletes a subkey and its values

#include <WinAPIReg.au3>
_WinAPI_RegDeleteKey ( $vKey [, $sSubKey = '' [, $iSamDesired = Default]] )

## Parameters

$vKey | Name of the key to be open (see remarks). or Handle to an open registry key. The access rights of this key do not affect the delete operation. This handle is returned by the _WinAPI_RegCreateKey() or _WinAPI_RegOpenKey() function, or it can be one of the following predefined keys: $HKEY_CLASSES_ROOT $HKEY_CURRENT_CONFIG $HKEY_CURRENT_USER $HKEY_LOCAL_MACHINE $HKEY_USERS
$sSubKey | [optional] The name of the key to be deleted. It must be a subkey of the key that $hKey identifies, but it cannot have subkeys.
$iSamDesired | [optional] An access mask the specifies the platform-specific view of the registry. This parameter can be one of the following values: $KEY_WOW64_32KEY for an 32-bit Key $KEY_WOW64_64KEY for an 64-bit Key By Default the key correspond to the @AutoItX64 value.

## Return Value

Success: | 1.
Failure: | 0 and sets the @error flag to non-zero, @extended flag may contain the system error code.

## Remarks

$vKey can be a string containing the requested subkey in this case $sSubKey must be empty
A deleted key is not removed until the last handle to it is closed.
On WOW64, 32-bit applications view a registry tree that is separate from the registry tree that 64-bit applications view. This function enables an application to delete an entry in the alternate registry view.
The subkey to be deleted must not have subkeys. To delete a key and all its subkeys, you need to enumerate the subkeys and delete them individually. To delete keys recursively, use the _WinAPI_RegDeleteTree() or _WinAPI_RegDeleteTreeEx() function.

## Related

_WinAPI_RegCreateKey, _WinAPI_RegOpenKey, _WinAPI_RegDeleteTree, _WinAPI_RegDeleteTreeEx

## See Also

Search RegDeleteKeyEx in MSDN Library.

## Example

    #RequireAdmin

    #include <Debug.au3>
    #include <WinAPIReg.au3>

    _DebugSetup(Default, True)

    Example()

    Func Example()
        Local $sKey = "HKEY_LOCAL_MACHINE"
        Local $sSubKey = "SOFTWARE\MyApp"

        Local $sMyKey = $sKey & "\" & $sSubKey
        _DebugReport('@@ Debug(' & @ScriptLineNumber & ') : $sMyKey = ' & $sMyKey & @CRLF & '>Error code: ' & @error & '    Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF)

        Local $hOpenKey = _WinAPI_RegCreateKey($sMyKey)
        _DebugReport('@@ Debug(' & @ScriptLineNumber & ') : $hOpenKey = ' & $hOpenKey & @CRLF & '>Error code: ' & @error & '    Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF)

        Local $iRegDelete = _WinAPI_RegDeleteKey($hOpenKey)
        _DebugReport('@@ Debug(' & @ScriptLineNumber & ') : $iRegDelete = ' & $iRegDelete & @CRLF & '>Error code: ' & @error & '    Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF)

        Local $iRegClose = _WinAPI_RegCloseKey($hOpenKey)
        _DebugReport('@@ Debug(' & @ScriptLineNumber & ') : $iRegClose = ' & $iRegClose & @CRLF & '>Error code: ' & @error & '    Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF)

    EndFunc   ;==>Example