Results 1 to 16 of 16

Thread: [RESOLVED] Help! cannot delete registry [x64] subkeys

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2013
    Posts
    330

    Resolved [RESOLVED] Help! cannot delete registry [x64] subkeys

    Hi everyone,

    I really need some help on deleting [x64] registry subkeys
    I run my code and it shows that the keys were deleted
    but when I search for the subkey everything seem like if nothing happened!
    Code:
    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    DelRegKeys "SOFTWARE\Classes\Interface\{1A2A195A-A0F9-4006-AF02-3F05EEFDE792}", HKEY_LOCAL_MACHINE
    any help will be appreciate

  2. #2
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    389

    Re: Help! cannot delete registry [x64] subkeys

    VBscript \ VB6 ?
    Not quite sure as to why you're using StdRegProv, but something did catch my eyes
    MSDN Documentation says HKEY_LOCAL_MACHINE should be an unsigned integer, meaning long in vb. is it defined ? (&H80000002)

    Name:  Untitled.jpg
Views: 981
Size:  19.4 KB

    Also, assuming "DelRegKeys" is a function you made, verify its content.
    should contain something like:
    Code:
    Const HKEY_LOCAL_MACHINE as Long =&H80000002 
    Dim lngRaisedError as Long
    
    Dim KeyPath as String
        KeyPath = "SOFTWARE\Classes\Interface\{1A2A195A-A0F9-4006-AF02-3F05EEFDE792}"
    
    lngRaisedError = oReg.DeleteKey(HKEY_LOCAL_MACHINE, KeyPath)
    
    If (lngRaisedError = 0) And (Err.Number = 0) Then Msgbox "Success!"
    which is the way to delete a key
    Last edited by stum; May 26th, 2015 at 12:01 AM.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2013
    Posts
    330

    Re: Help! cannot delete registry [x64] subkeys

    Hi stum, yes, is visual basic 6 code, not vbs.
    and yes, I have a module bas with something similar.
    I mean, my code works as long as the registry subkey is not [x64]

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2013
    Posts
    330

    Re: Help! cannot delete registry [x64] subkeys

    Name:  Run-time error.jpg
Views: 992
Size:  21.0 KB
    I tried your example, but I get an error, a run-time error

  5. #5
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    759

    Re: Help! cannot delete registry [x64] subkeys

    VB6 can only produce 32-bit applications and 32-bit applications can only work within a 32-bit "sandbox" inside the Registry; the bit that "little" applications are allowed to play in.

    https://msdn.microsoft.com/en-us/lib...or=-2147217396

    To update some sections of the entire Registry, you have to use a proper, "grown-up", 64-bit application and that means porting your application to a.n.other language. VB6 simply will not do it.

    Regards, Phill W.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2013
    Posts
    330

    Re: Help! cannot delete registry [x64] subkeys

    The page you shared talks about 32-bit and 64-bit Application Data in the Registry,
    But not the other things you were talking about, like the: vb6 does not handle such task.

  7. #7
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    759

    Re: Help! cannot delete registry [x64] subkeys

    Did you try following any of the links from that page? One of them takes you to "Accessing an Alternate Registry View" (https://msdn.microsoft.com/en-us/lib...v=vs.85).aspx) which clearly states:

    > "The RegDeleteKey function cannot be used to access an alternate registry view."

    So, from a 32-bit process, which is the only kind that VB6 can produce, you can't [even] use the "Alternate Registry View" mechanism to delete keys from the full, 64-bit Registry.

    The only way you can do this is from a 64-bit process. I'd suggest the "big" version of regedit (there are two on x64 machines), into which you can feed a .reg file that will delete these keys (prefix the key name with a "-").
    Also, that process is going to have run "elevated", because you're deleting stuff from under HKEY_LOCAL_MACHINE, which "regular" users cannot do without first passing through the U.A.C. Challenge.
    And I'm not even sure why you'd want to manually delete InterfaceIds anyway; I'd have thought an [un]installer would be the proper way to do that.

    Regards, Phill W.

  8. #8
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Help! cannot delete registry [x64] subkeys

    Quote Originally Posted by Phill.W View Post
    One of them takes you to "Accessing an Alternate Registry View" (https://msdn.microsoft.com/en-us/lib...v=vs.85).aspx) which clearly states:

    > "The RegDeleteKey function cannot be used to access an alternate registry view."

    So, from a 32-bit process, which is the only kind that VB6 can produce, you can't [even] use the "Alternate Registry View" mechanism to delete keys from the full, 64-bit Registry.
    That very same topic, however, recommended an alternative API (RegDeleteKeyEx) capable of accessing either a 32-bit or 64-bit key from either a 32-bit or 64-bit application.



    @ Coding

    Try the following recursive routine and see whether 32-bit VB6 apps can indeed access the 64-bit registry view:

    Code:
    Option Explicit
    
    Private Enum PredefinedRegKeys
        HKEY_CLASSES_ROOT = &H80000000
        HKEY_CURRENT_USER = &H80000001
        HKEY_LOCAL_MACHINE = &H80000002
        HKEY_USERS = &H80000003
        HKEY_CURRENT_CONFIG = &H80000005
    End Enum
    #If False Then
        Dim HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, _
        HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG
    #End If
    
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function RegDeleteKeyExW Lib "advapi32.dll" (ByVal hKey As Long, ByVal lpSubKey As Long, ByVal samDesired As Long, Optional ByVal Reserved As Long) As Long
    Private Declare Function RegEnumKeyExW Lib "advapi32.dll" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As Long, ByRef lpcName As Long, Optional ByVal lpReserved As Long, Optional ByVal lpClass As Long, Optional ByRef lpcClass As Long, Optional ByVal lpftLastWriteTime As Long) As Long
    Private Declare Function RegOpenKeyExW Lib "advapi32.dll" (ByVal hKey As Long, ByVal lpSubKey As Long, ByVal ulOptions As Long, ByVal samDesired As Long, ByRef phkResult As Long) As Long
    Private Declare Function RegQueryInfoKeyW Lib "advapi32.dll" (ByVal hKey As Long, Optional ByVal lpClass As Long, Optional ByRef lpcClass As Long, Optional ByVal lpReserved As Long, Optional ByRef lpcSubKeys As Long, Optional ByRef lpcMaxSubKeyLen As Long, Optional ByRef lpcMaxClassLen As Long, Optional ByRef lpcValues As Long, Optional ByRef lpcMaxValueNameLen As Long, Optional ByRef lpcMaxValueLen As Long, Optional ByRef lpcbSecurityDescriptor As Long, Optional ByVal lpftLastWriteTime As Long) As Long
    Private Declare Function SysReAllocStringLen Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long, Optional ByVal Length As Long) As Long
    Code:
    Private Function RegDelTree(ByVal hKeyRoot As PredefinedRegKeys, ByRef SubKey As String) As Boolean
        Const ERROR_SUCCESS = 0&, KEY_READ = &H20019, KEY_WOW64_64KEY = &H100&, Wow6432Node = "Wow6432Node" & vbNullChar
        Dim hKey As Long, i As Long, nBufferLen As Long, sBuffer As String
    
        If RegDeleteKeyExW(hKeyRoot, StrPtr(SubKey), KEY_WOW64_64KEY) = ERROR_SUCCESS Then
            RegDelTree = True
    
        ElseIf RegOpenKeyExW(hKeyRoot, StrPtr(SubKey), 0&, KEY_READ Or KEY_WOW64_64KEY, hKey) = ERROR_SUCCESS Then
            If RegQueryInfoKeyW(hKey, , , , i, nBufferLen) = ERROR_SUCCESS Then
                SysReAllocStringLen VarPtr(sBuffer), , nBufferLen
    
                For i = i - 1& To 0& Step -1&
                    nBufferLen = Len(sBuffer) + 1&
    
                    If RegEnumKeyExW(hKey, i, StrPtr(sBuffer), nBufferLen) = ERROR_SUCCESS Then
                        If InStr(1&, sBuffer, Wow6432Node) <> 1& Then
                            If Not RegDelTree(hKeyRoot, SubKey & ("\" & Left$(sBuffer, nBufferLen))) Then Exit For
                        End If
                    End If
                Next
            End If
    
            hKey = RegCloseKey(hKey):    Debug.Assert hKey = ERROR_SUCCESS
    
            If i = -1& Then RegDelTree = RegDeleteKeyExW(hKeyRoot, StrPtr(SubKey), KEY_WOW64_64KEY) = ERROR_SUCCESS
        End If
    End Function
    Code:
    MsgBox "RegDelTree = " & RegDelTree(HKEY_LOCAL_MACHINE, "SOFTWARE\Classes\Interface\{1A2A195A-A0F9-4006-AF02-3F05EEFDE792}"), vbInformation

    BTW, the topic Requesting WMI Data on a 64-bit Platform shows that is also possible for 32-bit processes to tell WMI to request data from 64-bit providers. Although the examples there demonstrates how to access the 32-bit registry hive from either a 32-bit or 64-bit process, it's simple enough to modify the codes to do the opposite.
    Last edited by Bonnie West; May 28th, 2015 at 11:00 PM.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2013
    Posts
    330

    Re: Help! cannot delete registry [x64] subkeys

    Bonnie West, I'm testing the code right now, even if it does'n work, thanks for giving me hope.
    So this is what I'm doing, I placed the following code in a module:
    Code:
    Option Explicit
    
    Private Enum PredefinedRegKeys
    HKEY_CLASSES_ROOT = &H80000000
    HKEY_CURRENT_USER = &H80000001
    HKEY_LOCAL_MACHINE = &H80000002
    HKEY_USERS = &H80000003
    HKEY_CURRENT_CONFIG = &H80000005
    End Enum
    #If False Then
    Dim HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, _
    HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG
    #End If
    
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function RegDeleteKeyExW Lib "advapi32.dll" (ByVal hKey As Long, ByVal lpSubKey As Long, ByVal samDesired As Long, Optional ByVal Reserved As Long) As Long
    Private Declare Function RegEnumKeyExW Lib "advapi32.dll" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As Long, ByRef lpcName As Long, Optional ByVal lpReserved As Long, Optional ByVal lpClass As Long, Optional ByRef lpcClass As Long, Optional ByVal lpftLastWriteTime As Long) As Long
    Private Declare Function RegOpenKeyExW Lib "advapi32.dll" (ByVal hKey As Long, ByVal lpSubKey As Long, ByVal ulOptions As Long, ByVal samDesired As Long, ByRef phkResult As Long) As Long
    Private Declare Function RegQueryInfoKeyW Lib "advapi32.dll" (ByVal hKey As Long, Optional ByVal lpClass As Long, Optional ByRef lpcClass As Long, Optional ByVal lpReserved As Long, Optional ByRef lpcSubKeys As Long, Optional ByRef lpcMaxSubKeyLen As Long, Optional ByRef lpcMaxClassLen As Long, Optional ByRef lpcValues As Long, Optional ByRef lpcMaxValueNameLen As Long, Optional ByRef lpcMaxValueLen As Long, Optional ByRef lpcbSecurityDescriptor As Long, Optional ByVal lpftLastWriteTime As Long) As Long
    Private Declare Function SysReAllocStringLen Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long, Optional ByVal Length As Long) As Long
    
    Private Function RegDelTree(ByVal hKeyRoot As PredefinedRegKeys, ByRef SubKey As String) As Boolean
    Const ERROR_SUCCESS = 0&, KEY_READ = &H20019, KEY_WOW64_64KEY = &H100&, Wow6432Node = "Wow6432Node" & vbNullChar
    Dim hKey As Long, i As Long, nBufferLen As Long, sBuffer As String
    
    If RegDeleteKeyExW(hKeyRoot, StrPtr(SubKey), KEY_WOW64_64KEY) = ERROR_SUCCESS Then
    RegDelTree = True
    
    ElseIf RegOpenKeyExW(hKeyRoot, StrPtr(SubKey), 0&, KEY_READ Or KEY_WOW64_64KEY, hKey) = ERROR_SUCCESS Then
    If RegQueryInfoKeyW(hKey, , , , i, nBufferLen) = ERROR_SUCCESS Then
    SysReAllocStringLen VarPtr(sBuffer), , nBufferLen
    
    For i = i - 1& To 0& Step -1&
    nBufferLen = Len(sBuffer) + 1&
    
    If RegEnumKeyExW(hKey, i, StrPtr(sBuffer), nBufferLen) = ERROR_SUCCESS Then
    If InStr(1&, sBuffer, Wow6432Node) <> 1& Then
    If Not RegDelTree(hKeyRoot, SubKey & ("\" & Left$(sBuffer, nBufferLen))) Then Exit For
    End If
    End If
    Next
    End If
    
    hKey = RegCloseKey(hKey):    Debug.Assert hKey = ERROR_SUCCESS
    
    If i = -1& Then RegDelTree = RegDeleteKeyExW(hKeyRoot, StrPtr(SubKey), KEY_WOW64_64KEY) = ERROR_SUCCESS
    End If
    End Function
    Then I called the funtion like this:
    Code:
    Private Sub Command1_Click()
    MsgBox "RegDelTree = " & RegDelTree(HKEY_LOCAL_MACHINE, "SOFTWARE\Classes\Interface\{1A2A195A-A0F9-4006-AF02-3F05EEFDE792}"), vbInformation
    End Sub
    but I am getting an error, this error: "Compile Error: Sub or Function not defined".
    it points to: "RegDelTree "
    Last edited by Coding; May 28th, 2015 at 09:10 PM.

  10. #10
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Help! cannot delete registry [x64] subkeys

    Quote Originally Posted by Coding View Post
    ... I placed the following code in a module:

    . . .

    but I am getting an error, this error: "Compile Error: Sub or Function not defined".
    it points to: "RegDelTree "
    If you want the RegDelTree function to be accessible from anywhere in your project, you'll have to change its scope from Private to Public. You'll also have to do the same modification to the PredefinedRegKeys enum.
    Last edited by Bonnie West; May 28th, 2015 at 11:10 PM.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2013
    Posts
    330

    Re: Help! cannot delete registry [x64] subkeys

    Bonnie, I was able to make it work ! Thank you!
    But one question Bonnie, this example is reading and deleting at the same time?
    because now with the function working properly I was not able to find that subkey no more.
    if the answer is no, how could I change it so it delete the subkey I tell it to delete for me?

  12. #12
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Help! cannot delete registry [x64] subkeys

    Quote Originally Posted by Coding View Post
    But one question Bonnie, this example is reading and deleting at the same time?
    That code retrieves a handle to the specified key, obtains a couple of details about its subkeys, enumerates its subkeys, recurses into those subkeys and finally deletes in reverse order the entire tree of subkeys rooted at the specified key. The only thing it "reads" are 2 details about the subkeys - the count of subkeys and the length of the longest subkey name.

    Quote Originally Posted by Coding View Post
    if the answer is no, how could I change it so it delete the subkey I tell it to delete for me?
    That function deletes the specified key, its values, its subkeys (if any) and their values. A key cannot be deleted without deleting its subkeys first.

    Quote Originally Posted by Coding View Post
    Bonnie, I was able to make it work ! Thank you!
    You're welcome!

    Don't forget to mark this thread Resolved!

    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2013
    Posts
    330

    Re: Help! cannot delete registry [x64] subkeys

    Bonnie West! ..Thank You! so much for not giving up on me
    I just wanted to say thank you and confirm that it worked like a charm!
    I tested the final code on: Windows 7 x64-bits, Windows 8, and also Windows 8.1
    When the impossible just seem to be impossible there is always a hope at the end.
    My respect for Bonnie West

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2013
    Posts
    330

    Re: [RESOLVED] Help! cannot delete registry [x64] subkeys

    Hello guys, how could I use this code without the MsgBox?
    Code:
    MsgBox "RegDelTree = " & RegDelTree(HKEY_LOCAL_MACHINE, "SOFTWARE\Classes\Interface\{1A2A195A-A0F9-4006-AF02-3F05EEFDE792}"), vbInformation
    I already tried two diferent ways, but I get an error, this is an example from Bonnie West.
    Thanks in advance

  15. #15
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: [RESOLVED] Help! cannot delete registry [x64] subkeys

    Try this:

    Code:
    RegDelTree HKEY_LOCAL_MACHINE, "SOFTWARE\Classes\Interface\{1A2A195A-A0F9-4006-AF02-3F05EEFDE792}"

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2013
    Posts
    330

    Re: [RESOLVED] Help! cannot delete registry [x64] subkeys

    Thank You! So Much jpbro! that did the trick!!!

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