-
All I need to do is delete 2 registry keys and add them back to delete any values and subkeys. The problem now (using Kedaman's Registry module) is that if there are subkeys in a key, the parent key doesn't get deleted.
How can I delete a key that contains subkeys?
This is what I have so far.
Code:
DeleteKey "HKEY_USERS\.Default\Software\Microsoft\Windows\CurrentVersion\Explorer\StreamMRU"
DeleteKey "HKEY_USERS\.Default\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams"
CreateKey "HKEY_USERS\.Default\Software\Microsoft\Windows\CurrentVersion\Explorer\StreamMRU"
CreateKey "HKEY_USERS\.Default\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams"
Thanks in advance,
-
Theres two functions, Subkeys and keyvalues, Subkeys returns an array of all subkeys and keyvalues returns all values of a key. You could do something recursive:
Code:
DeleteKeyTree(key as string)
dim n
For each n in subkeys(key)
DeleteKeyTree n
next n
deletekey key
end sub
Haven't tested if it works but it should :)
-
-
I get a compile error.
"ByRef argument type mismatch"
at
-
Use ByVal in your function.
Code:
Function MyFunc(ByVal Arg As Integer)
-
This works if there are subkeys otherwise I get an error.
Run-Time error '92':
For loop not initialized
Code:
Private Sub DeleteKeyTree(key As String)
Dim n
For Each n In SubKeys(key)
DeleteKey key & "\" & n
Next n
DeleteKey key
End Sub
-
oooh
ok, as i said i haven't tested it, but that should do it dcarlson :) There's no way to tell if an array is empty in vb so you need to use error handling.
Private Sub DeleteKeyTree(key As String)
Dim n,arr() as string
arr=SubKeys(key)
on error resume next
n=ubound(arr)
if err=0 then
on error goto 0
For Each n In arr
DeleteKey key & "\" & n
Next n
end if
DeleteKey key
End Sub
-
Well actually it doesn't mean it's a error, the key just doesn't have any subkeys :) If you want to have your errorhandling left, you could still avoid getting unnessesary loads of for loop not initialized errors:
Code:
'replace
Else
'with
Elseif err.number=92 then 'do nothing
Else
-
The purpose of this snippet is to delete keys from a Compaq laptop that conflicts with the install IE. So instead of stepping through the deleting of entries for each laptop (which is over 20) they'll run the app and if there's any problems then I'll step them through it.
Again thanks for all the help.