DeleteKey
Deletes a registry key that has no subkeys.
Syntax: object.DeleteKey ( RootKey, KeyPath )
- RootKey
- required A RegKeyspace value identifying the root hive — for example,
HKEY_CURRENT_USERorHKEY_LOCAL_MACHINE. - KeyPath
- required A String specifying the path of the key to delete, relative to RootKey. Segments are separated by backslashes — for example,
"Software\MyApp".
Returns True if the key was deleted successfully, or False if the call failed.
Important
The underlying Win32 RegDeleteKey call succeeds only when the target key has no subkeys. If the key contains subkeys, the call returns False. Use DeleteKeyEx to remove a key together with all its subkeys and values.
Example
This example removes the Settings key under HKEY_CURRENT_USER\Software\MyApp and reports whether the deletion succeeded. The call fails if the key has subkeys.
Dim reg As New RegCls
If reg.DeleteKey(HKEY_CURRENT_USER, "Software\MyApp\Settings") Then
Debug.Print "Key deleted."
Else
Debug.Print "Deletion failed -- key may have subkeys or may not exist."
End If
See Also
- DeleteKeyEx – removes a key and all its subkeys and values recursively
- DeleteValue function
- CreateKey function
- KeyExists function