Kallely
Fri May 27 12:29:18 CDT 2005
Thanks for your help
Sajan
"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:%23rINMCuYFHA.3320@TK2MSFTNGP12.phx.gbl...
> Kallely Sajan wrote:
>
> > Hi everybody,
> > How would I delete a registry value with a name "abc\def\ghi" using
> > RegDelete(). Having a back slash in the names makes the RegDelete()
think
> > that it is a registry key hierarchy an not a value name.
> Hi,
>
> Backslash in registry values is a known issue (and not allowed) in WSH.
>
> Two workarounds:
>
> A)
> You can delete keys (with subkeys) and values with a registry file.
>
> Delete key:
> [-HKEY_LOCAL_MACHINE\SOFTWARE\Brix\Testapp2]
>
> Delete value:
> [HKEY_LOCAL_MACHINE\SOFTWARE\Brix\Testapp2]
> "abc\\def\\ghi"=-
>
> NOTE: One backslash in the value name must be represented by two
> backslashes in the registry file (because backslash is an escape
> character in registry files)
>
> You can use FSO to create this registry file on the fly, and then
> import it silently with regedit /s, like this:
>
> '--------------------8<----------------------
> Set oShell = CreateObject("WScript.Shell")
> Set oFSO = CreateObject("Scripting.FileSystemObject")
>
> sTempRegFile = oFSO.GetSpecialFolder(2).ShortPath & "\" & oFSO.GetTempName
>
> Set fRegFile = oFSO.CreateTextFile(sTempRegFile, True)
>
> fRegFile.WriteLine "REGEDIT4"
> fRegFile.WriteLine
> fRegFile.WriteLine "[HKEY_LOCAL_MACHINE\SOFTWARE\Foo]"
>
> ' Inside a quoted string, you need to use two quotes to get one effective.
> fRegFile.WriteLine """abc\\def\\ghi""=-"
>
> ' always end registry files with a blank line.
> fRegFile.WriteLine
> fRegFile.Close
>
> oShell.Run "regedit.exe /s " & sTempRegFile, 0, True
> oFSO.DeleteFile sTempRegFile, True
> '--------------------8<----------------------
>
>
>
> B)
> Use WMI's StdRegProv (Standard Registry Provider) and it's DeleteValue
> method. WMI comes default with WMe/W2k/WXP, can be installed on W9x/WNT.
>
> WMI Class StdRegProv:
>
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/stdregprov.asp
>
> See "Delete Registry Values" here:
>
http://www.microsoft.com/technet/scriptcenter/scripts/os/registry/default.mspx
>
>
>
>
> --
> 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/default.mspx