- Aug 21, 2002
- 18,368
- 11
- 81
Ok... so the deal is that I'm trying to delete some registry keys and their subkeys but the keys vary from machine to machine. And I need to recreate one (or not delete one, just modify some DWords).
So... all the keys I'm trying to delete are in a key that's constant... lets say...
System\CurrentControlSet\Control\Video
And the keys might be...
System\CurrentControlSet\Control\Video\Key1
System\CurrentControlSet\Control\Video\Key2
System\CurrentControlSet\Control\Video\Key3
System\CurrentControlSet\Control\Video\Key4
I need to get rid of Key 1, 2, and 3 and modify the values within Key4's subkeys but they have subkeys so the only way I've been able to script that is to use a subroutine that calls itself. The problem with that is that it deletes all of them... which would be OK because I can recreate them as long as I can pull Key4's name from the registry and store it so it's recreated with the correct name, but I've been having a hard time doing that.
I think I'm probably going about this in a round about way... but here's the script I have so far that's working perfectly for deleting them:
Unfortunately, the Parent key is the last key to be deleted in that recursion, so the last value of strKeyPath is the parent key... and I want to recreate System\CurrentControlSet\Control\Video\Key4... which wouldn't be a problem if Key4's name was constant, but it's not.
Any suggestions?
So... all the keys I'm trying to delete are in a key that's constant... lets say...
System\CurrentControlSet\Control\Video
And the keys might be...
System\CurrentControlSet\Control\Video\Key1
System\CurrentControlSet\Control\Video\Key2
System\CurrentControlSet\Control\Video\Key3
System\CurrentControlSet\Control\Video\Key4
I need to get rid of Key 1, 2, and 3 and modify the values within Key4's subkeys but they have subkeys so the only way I've been able to script that is to use a subroutine that calls itself. The problem with that is that it deletes all of them... which would be OK because I can recreate them as long as I can pull Key4's name from the registry and store it so it's recreated with the correct name, but I've been having a hard time doing that.
I think I'm probably going about this in a round about way... but here's the script I have so far that's working perfectly for deleting them:
Code:
Const HKCC = &H80000005
strComputer = "."
strKeyPath = "System\CurrentControlSet\Control\Video"
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
DeleteSubkeys HKCC, strKeypath
Sub DeleteSubkeys(HKCC, strKeypath)
objRegistry.EnumKey HKCC, strKeyPath, arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys HKCC, strKeyPath & "\" & strSubkey
Next
End If
objRegistry.DeleteKey HKCC, strKeyPath
End Sub
Unfortunately, the Parent key is the last key to be deleted in that recursion, so the last value of strKeyPath is the parent key... and I want to recreate System\CurrentControlSet\Control\Video\Key4... which wouldn't be a problem if Key4's name was constant, but it's not.
Any suggestions?
