Results 1 to 16 of 16

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

Threaded View

  1. #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.

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