Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Platforms: Win 32s, Win 95/98, Win NT
RegDeleteKey deletes a key from the registry. The key to delete cannot have any subkeys under it or else the delete operation will fail. Under Win NT, the function will also fail if there are any values still under the key to delete. However, under Win 95/98, the function will still work; the key and all its associated values will be deleted. The function returns 0 if successful, or a non-zero error code if an error occured.
Example:
' Delete the registry key "Software\MyProgram\Config" under the base
' key HKEY_LOCAL_MACHINE. Indicate any failure conditions.
Dim retval As Long ' return value
' Attempt to delete the desired registry key.
retval = RegDeleteKey(HKEY_LOCAL_MACHINE, "Software\MyProgram\Config")
If retval <> 0 Then
Debug.Print "Delete operation failed. The key may have subkeys and/or values under it."
Debug.Print "Of course, the key might just not exist at all."
End If
Related Calls: RegCreateKeyEx, RegDeleteValue
Category: Registry
Back to the index.