Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-05-13
3
Medium Priority
?
1,012 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 1000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

963 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