Solved

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

Posted on 2009-05-13
3
942 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

930 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

12 Experts available now in Live!

Get 1:1 Help Now