/build/static/layout/Breadcrumb_cap_w.png

In Visual Basic Script, how do you Enumerate all the subkeys of a given registry key when it is a 64 bit key?

I have some visual basic script code to recursively delete registry keys.  It works fine on the 32bit keys (under HKEY_LOCAL_MACHINE\Software\Wow6432Node) but does not execute under the 64 bit keys (at HKEY_LOCAL_MACHINE\Software).  What do I need to make to the code to get this to execute properly for both 32 and 64 bit keys?  I've worked on this for a while scouring the internet and making several approaches.  Hopefully someone out there has the solution.   

Begin Code:

'----------------------------------------------------------

Sub DeleteSubkeys(Key, strKeyPath)
 Dim arrSubkeys, strSubkey
    objRegistry.EnumKey Key, strKeyPath, arrSubkeys

    If IsArray(arrSubkeys) Then
        For Each strSubkey In arrSubkeys
            DeleteSubkeys Key, strKeyPath & "\" & strSubkey
        Next
    End If

    objRegistry.DeleteKey Key, strKeyPath
End Sub

'----------------------------------------------------------

End of Code

BTW - I did run across this code at ITNinjas while I was looking for the 64 bit solution so the general problem has been worked on before.


0 Comments   [ + ] Show comments

Answers (2)

Posted by: SMal.tmcc 4 years ago
Red Belt
1

Call the 64 bit vbs exe file not the 32.  If you are using kace to call the script the client is 32 bit so it calls the 32bit vbs exe file (cscript or wscript)  those files exist as 32 and 64 bit executables.

On a x64 call the exe using the sysnative command vs standard path variables.

path:

c:\windows\sysnative

executable

Cscript.exe

parameters

runthis.vbs



Posted by: lkitsmiller 4 years ago
Yellow Belt
1

I did find the answer.  Change the 64 to a 32 when referring to 32 bit keys.  Detailed code below:

Option Explicit
Dim oCtx, oLocator, oReg, Return, arrSubKeys, strSubKey

Const HKEY_LOCAL_MACHINE = &H80000002

DeleteSubkeys HKEY_LOCAL_MACHINE, "Software\Mykey", 64

Sub DeleteSubkeys (Key, strKeyPath, RegType)

 Set oCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
 oCtx.Add "__ProviderArchitecture", RegType

 Set oLocator = CreateObject("Wbemscripting.SWbemLocator")
 Set oReg = oLocator.ConnectServer("", "root\default", "", "", , , , oCtx).Get("StdRegProv")

 oReg.EnumKey Key, strKeyPath, arrSubKeys
 If IsArray(arrSubkeys) Then
  For Each strSubkey In arrSubkeys
   DeleteSubkeys Key, strKeyPath & "\" & strSubkey, RegType
  Next
 End If
    Return = oReg.DeleteKey(Key, strKeyPath)
End Sub


 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ