Solved

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

Posted on 2009-05-13
3
933 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now