RegDeleteKey Function

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.

hKey
Either a handle to a registry key which the key to delete is under (note that this cannot itself be the key to delete), or one of the following flags specifying a base registry key:
HKEY_CLASSES_ROOT = &H80000000
The HKEY_CLASSES_ROOT base key.
HKEY_CURRENT_CONFIG = &H80000005
The HKEY_CURRENT_CONFIG base key.
HKEY_CURRENT_USER = &H80000001
The HKEY_CURRENT_USER base key.
HKEY_DYN_DATA = &H80000006
The HKEY_DYN_DATA base key.
HKEY_LOCAL_MACHINE = &H80000002
The HKEY_LOCAL_MACHINE base key.
HKEY_PERFORMANCE_DATA = &H80000004
The HKEY_PERFORMANCE_DATA base key.
HKEY_USERS = &H80000003
The HKEY_USERS base key.
lpSubKey
The name of the subkey under hKey to delete.

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.


Go to Paul Kuliniewicz's Home Page.
E-mail: rogue953@hotmail.com
This page is at http://skyscraper.fortunecity.com/transmission/45/api/r/regdeletekey.html