Solved

RegDelete a String Value that contains a directory path...

Posted on 2009-05-13
3
964 Views
Last Modified: 2012-05-06
I am having issues deleting a registy string value that contains a path... C:\DirectoryPath

The registry key is... HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders\

The string value is... C:\DirectoryPath

I have used \ and \\ between the two, but am still getting errors.

I expect it is just an issue of string structuring, I can easily do this in cmd form, but this was a new challenge.
set WshShell = CreateObject("WScript.Shell")
 
strValue="HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders\C:\DirectoryPath"
WshShell.RegDelete strValue

Open in new window

0
Comment
Question by:chadbalser
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
abel earned 250 total points
ID: 24380737
The simple answer is: it cannot be done. The WSH does not support deleting values that have backslashes in their names: http://www.ureader.com/msg/1677274.aspx.

But the good news is, it can be resolved by using WMI instead. Try the following for your key (it works, I tested):

Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders"
strKeyValue = "D:\test\test\"
 
oReg.DeleteValue HKEY_LOCAL_MACHINE, strKeyPath, strKeyValue

Open in new window

0
 
LVL 1

Author Comment

by:chadbalser
ID: 24381257
Thanks,  I had figured that was the case in my searches - thanks for the alternate solution too.

Chad
0
 
LVL 39

Expert Comment

by:abel
ID: 24382460
you're welcome, glad it works now :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question