Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
RegDeleteKey deletes a key from the registry, along with any values it may contain. Windows NT, 2000: The function will fail if there are any subkeys under the key to delete. Windows 95, 98: The function will delete any subkeys under the key to be deleted, instead of failing.
If successful, the function returns zero. If an error occured, the function returns a nonzero error code.
None.
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_DYN_DATA = &H80000006
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_PERFORMANCE_DATA = &H80000004
Const HKEY_USERS = &H80000003
Example:
Attempt to delete the registry key "HKEY_LOCAL_MACHINE\Software\MyProgram\Config" when the user clicks button Command1. (Of course, typically you would never give the user an option like this, but this is just a simple example.) Depending on your Windows platform, this function may fail if there are any subkeys under this key. To run this example, you first need to place a command button named Command1 on a form window.
' This code is licensed according to the terms and conditions listed here.
' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, _
ByVal lpSubKey As String) As Long
Public Const HKEY_LOCAL_MACHINE = &H80000002
Private Sub Command1_Click()
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."
Else
Debug.Print "Deletion successful."
End If
End Sub
RegCreateKeyEx, RegDeleteValue
Go back to the Function listing.
Go back to the Reference section index.
Last Modified: September 24, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/r/regdeletekey.html