Solved

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

Posted on 2009-05-13
3
971 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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