Mark
Tue Dec 23 14:58:36 CST 2003
Thanks Torgeir, that works great!!
Mark
"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:3FE75F26.D93A78F2@hydro.com...
> Mark wrote:
>
> > 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".
>
>
> --
> 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
>
>