Thanks.
Mark
Hi
To delete a key that have subkeys, you can use VBScript\WMI and a recursive sub
(a sub that calls itself) to delete the key(s), see sub DeleteRegistryKey in
the link below:
http://groups.google.com/groups?selm=3FCCD280.8B890181%40hydro.com
You can also delete a registry key with any sub-keys with a registry file:
http://groups.google.com/groups?selm=3FCE6DF8.830634EA%40hydro.com
--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter
Mark
"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:3FE73FBA...@hydro.com...
> I copied that script and when I run it, it does not delete the registry key.
> I remarked out the "On Error Resume Next" line and ran it again and I get an
> error on the "For Each sSubKey in aSubKeys" line saying that the "Object not
> a collection". Any ideas what I need to do?
Oops, you got the version that works on Win2k SP2 and lower only...
This one will work on all Win2k and WinXP computers, regardless of SP level
(added an IsArray(aSubKeys) test):
Const HKLM = &H80000002
sKey = "System\CurrentControlSet\Services\Myservice"
Set oReg = GetObject _
("WinMgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv")
DeleteRegistryKey HKLM, sKey
Sub DeleteRegistryKey(ByVal sHive, ByVal sKey)
Dim aSubKeys, sSubKey, iRC
On Error Resume Next
iRC = oReg.EnumKey(sHive, sKey, aSubKeys)
If iRC = 0 And IsArray(aSubKeys) Then
For Each sSubKey In aSubKeys
If Err.Number <> 0 Then
Err.Clear
Exit Sub
End If
DeleteRegistryKey sHive, sKey & "\" & sSubKey
Next
End If
oReg.DeleteKey sHive, sKey
End Sub
> I did not try the reg file
> because I want to stick with vbscript, the script that I am using does other
> things in addition to modifying the registry.
You can use this registry file from a vbscript file as well, using the
FileSystemObject to create the registry file on the fly and then shell out
(using the Run method) and run regedit.exe /s "some reg file".
Mark
"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:3FE75F26...@hydro.com...