# Function Reference

# RegDelete

Deletes a key or value from the registry.

RegDelete ( "keyname" [, "valuename"] )

## Parameters

keyname | The registry key to delete.
valuename | [optional] The valuename to delete.

## Return Value

Success: | 1.
Special: | 0 if the key/value does not exist.
Failure: | 2 if error deleting key/value and sets the @error flag to non-zero.
@error: | 1 = unable to open requested key 2 = unable to open requested main key 3 = unable to remote connect to the registry -1 = unable to delete requested value -2 = unable to delete requested key/value

## Remarks

A registry key must start with "HKEY_LOCAL_MACHINE" ("HKLM") or "HKEY_USERS" ("HKU") or "HKEY_CURRENT_USER" ("HKCU") or "HKEY_CLASSES_ROOT" ("HKCR") or "HKEY_CURRENT_CONFIG" ("HKCC").
When running on 64-bit Windows if you want to delete a key or value specific to the 64-bit environment you have to suffix the HK... with 64 i.e. HKLM64.
To access the (Default) value use "" (an empty string) for the valuename.
Deleting from the registry is potentially dangerous--please exercise caution!
It is possible to access remote registries by using a keyname in the form "\\computername\keyname". To use this feature you must have the correct access rights.

## Related

RegEnumKey, RegEnumVal, RegRead, RegWrite

## Example

### Example 1

    #include <MsgBoxConstants.au3>

    Example()

    Func Example()
        ; Check if the registry key is already existing, so as not to damage the user's system.
        RegRead("HKEY_CURRENT_USER\Software\AutoIt_Example", "Key1")

        ; @error is set to non-zero when reading a registry key that doesn't exist.
        If Not @error Then
            MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst the temporary registry key. ""AutoIt_Example"" appears to already exist.")
            Return False
        EndIf

        ; Write a single REG_SZ value to the key "Key1".
        RegWrite("HKEY_CURRENT_USER\Software\AutoIt_Example", "Key1", "REG_SZ", "This is an example of RegWrite")

        ; Write the REG_MULTI_SZ value of "Line 1" and "Line 2". Always append an extra line-feed character when writing a REG_MULTI_SZ value.
        RegWrite("HKEY_CURRENT_USER\Software\AutoIt_Example", "Key2", "REG_MULTI_SZ", "Line 1" & @LF & "Line 2" & @LF)

        ; Write the REG_MULTI_SZ value of "Line 1". Always append an extra line-feed character when writing a REG_MULTI_SZ value.
        RegWrite("HKEY_CURRENT_USER\Software\AutoIt_Example", "Key3", "REG_MULTI_SZ", "Line 1" & @LF)

        ; Display a message to navigate to RegEdit.exe manually.
        MsgBox($MB_SYSTEMMODAL, "", "Open RegEdit.exe and navigate the registry key ""HKEY_CURRENT_USER\Software\AutoIt_Example"".")

        ; Delete the temporary registry key.
        RegDelete("HKEY_CURRENT_USER\Software\AutoIt_Example")
    EndFunc   ;==>Example

### Example 2

    #include <MsgboxConstants.au3>

    ;~ #RequireAdmin

    ; require admin privilege
    Local $sKey = "HKEY_LOCAL_MACHINE64\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders"
    Local $iRegWrite = RegWrite($sKey, "test", "REG_DWORD", "1")
    If $iRegWrite = 0 Then
        MsgBox($MB_ICONWARNING + $MB_TOPMOST, "REQUIRE Admin", "Cannot be created" & @CRLF & @CRLF & $sKey & @CRLF & @CRLF & 'Return = ' & $iRegWrite & @CRLF & '@error = ' & @error & @TAB & '@extended = ' & @extended & ' (0x' & Hex(@extended) & ')') ;### Debug MSGBOX
    Else
        MsgBox($MB_TOPMOST, "RegWrite", $sKey & @CRLF & @CRLF & "succesfully created")

        ; clean registry
        RegDelete($sKey, "test")
    EndIf

    ; Does not require admin privilege
    $sKey = "HKEY_CURRENT_USER\Software\Test"
    $iRegWrite = RegWrite("HKEY_CURRENT_USER\Software\Test", "test", "REG_DWORD", "1")
    If $iRegWrite = 0 Then
        ; Should not occur
        MsgBox($MB_ICONERROR + $MB_TOPMOST, "AutoIt Error", "Cannot create" & @CRLF & @CRLF & $sKey & @CRLF & @CRLF & 'Return = ' & $iRegWrite & @CRLF & '@error = ' & @error & @TAB & '@extended = ' & @extended & ' (0x' & Hex(@extended) & ')')
    Else
        If IsAdmin() Then
            MsgBox($MB_TOPMOST, "RegWrite", $sKey & " succesfully created")
        Else
            ConsoleWrite("- " & $sKey & " succesfully created" & @CRLF)
        EndIf

        ; clean registry
        RegDelete($sKey, "test")
        RegDelete($sKey)
    EndIf