Need VB6 API function to delete a registry key and all of it's subkeys and values

Posted on 2011-05-05
Last Modified: 2012-06-27
I need some code examples to delete a registry key and all of it's subkeys and values. I have found numerous examples on how to delete an empty key using RegDeleteKey, but no working examples on how to delete a key with subkeys and values. The example must use API calls, specifically RegDeleteKeyEx, not RegDeleteKey so that I can set my samDesired to KEY_WOW64_64KEY and use the alternate registry view and access 64 bit keys from a 32 bit app. I have had no problem finding code for querying , enumerating and creating 64 bit key/values, not sure why deleting a key is so difficult.
Question by:advcom
    LVL 1

    Expert Comment


    Author Comment

    Thanks for the reply, I had looked at that example already. It would only be able to delete 32 bit subkeys. From what I have read, you have to use RegDeleteKeyEx in order to delete 64 bit keys and it's syntax is different than RegDeleteKey.
    LVL 27

    Accepted Solution

    Change reg path first!
    Private Sub Command1_Click()
        Dim Str As String
        Str = "REG DELETE " & Chr(34) & "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" & CHR(34) & " /f /reg:64"
        Shell Str, vbNormalFocus
    End Sub

    Open in new window


    Author Closing Comment

    That was beautiful. It worked perfectly. I actually ran REG /? on a 7 command prompt before posting this question, but it did not show the 64 bit option. Thanks much
    LVL 27

    Expert Comment

    Tsss... This is M$ Top Secret :) I couldn't find this anywhere in MSDN
    Here it is (not directly about this switch, but if read between strings...):

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now