Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting Registry Keys that Have Subkeys using an Array

Status
Not open for further replies.
Jun 8, 2011
30
0
0
CA
Hello,

I am trying to remove a series of registry keys using a VBS script but I am unable to delete the keys that have subkeys. Keys that do not have subkeys delete appropriately. Here is the section of code I am working with.

-------------------------------
Dim strComputer, objRegistry, arrSubkeys, strSubkey
Dim arr_RegKeys(5,0)

arr_RegKeys(0,0) = "Installer\Features\05EF846EB0E72E5429DEBAF14D942339"
arr_RegKeys(1,0) = "Installer\Products\05EF846EB0E72E5429DEBAF14D942339"
arr_RegKeys(2,0) = "Installer\Features\23C393B6EC8A3664D9B5AE578C1D32C3"
arr_RegKeys(3,0) = "Installer\Products\23C393B6EC8A3664D9B5AE578C1D32C3"
arr_RegKeys(4,0) = "Installer\Features\8143882BBE1736F479BA22C2769E3985"
arr_RegKeys(5,0) = "Installer\Products\8143882BBE1736F479BA22C2769E3985"

Const HKEY_CLASSES_ROOT = &H80000000
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

DeleteSubkeys HKEY_CLASSES_ROOT, arr_RegKeys

Sub DeleteSubkeys(HKEY_CLASSES_ROOT, arr_RegKeys)

For i=0 to 5
objRegistry.EnumKey HKEY_CLASSES_ROOT, arr_RegKeys(i,0), arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys HKEY_CLASSES_ROOT, arr_RegKeys(i,0) & "\" & strSubkey
Next
End If
objRegistry.DeleteKey HKEY_CLASSES_ROOT, arr_RegKeys(i,0)
Next

End Sub

--------------------------

If anyone can tell me what I need to do to delete the keys with sub keys I greatly appreciate it.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top