Link to home
Start Free TrialLog in
Avatar of deming
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
Avatar of jkaios
jkaios
Flag of Marshall Islands image


'=================================[ FORM CODES ]=================================
Private Sub Command1_Click()
  If DeleteRegKey(HKEY_LOCAL_MACHINE, "\Software\MyApplication\MyValue") Then
    MsgBox "Registry key deleted"
  Else
    MsgBox "Failed to delete registry key"
  End If
End Sub
'=================================[ FORM CODES ]=================================


'=================================[ MODULE CODES ]=================================
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
'=================================[ MODULE CODES ]=================================
Avatar of deming
deming

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
Avatar of MilanKM
MilanKM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial