• Status: Solved
• Priority: Medium
• Security: Public
• Views: 1042

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

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
``````
0
• 2
1 Solution

Commented:
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
``````
0

Author Commented:
Thanks,  I had figured that was the case in my searches - thanks for the alternate solution too.

0

Commented:
you're welcome, glad it works now :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.