Results 1 to 9 of 9

Thread: Deleting from the registry

  1. #1

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179

    Wink

    what api/s would i need to use do delete whole branches of the regestry tree.

  2. #2
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185

    Smile

    You need to use the RegDeleteKey API to delete a registry key and all its subkeys and values.

    Here is some sample code on how to use it:


    Private Const HKEY_CURRENT_USER = &H80000001

    Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long

    Private Sub Form_Load()

    ' Delete the Test key
    Call RegDeleteKey(HKEY_CURRENT_USER, "Software\Test")

    End Sub

  3. #3

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179
    i've tried the code and i get a return value of 6 instead of 0.

    does it have to be done different under nt?

  4. #4

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179
    the problem was that i put the const into the module with the private statment, changed it to public and it now works.

    i now have the problem that it seems to delete the key but doesnt take effect straight away.

    if i colapse the tree in regedit and open it again my test key is still there but when i look at the contents regedit errors with ...

    Cannot open Test: Error while opening key.

  5. #5
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185
    If you want to see what your Registry API call has done to the registry in RegEdit, it is always best to press F5 to refresh it. RegEdit doesn't automatically update its self like the Windows Explorer does.

  6. #6

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179
    soz, should have thaught of that

  7. #7

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179
    it fails if the key has subkeys, is there a way around this?

  8. #8
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185
    What is the RegDeleteKey API call returning when it fails?

  9. #9

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179
    2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width