deming
asked on
Deleting a registry key
Hi,
I am trying to delete a registry key from my VB app. I am using following function to delete the registry key.
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
I am getting error code 2, and after looking in the WinError.h, it stands for ERROR_FILE_NOT_FOUND. I have given Full control to everyone for all the registry operations and for this hive as well.
Thanks
I am trying to delete a registry key from my VB app. I am using following function to delete the registry key.
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
I am getting error code 2, and after looking in the WinError.h, it stands for ERROR_FILE_NOT_FOUND. I have given Full control to everyone for all the registry operations and for this hive as well.
Thanks
ASKER
I am also using the same function. but i am getting the return value as 2. Can u explain me why??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
'=========================
Private Sub Command1_Click()
If DeleteRegKey(HKEY_LOCAL_MA
MsgBox "Registry key deleted"
Else
MsgBox "Failed to delete registry key"
End If
End Sub
'=========================
'=========================
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Enum RegHive
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
End Enum
Public Function DeleteRegKey(ByVal hKey As RegHive, ByVal sPath As String) As Long
Dim lResult As Long
lResult = RegDeleteKey(hKey, sPath)
DeleteRegKey = lResult
End Function
'=========================