Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fortage 1

Status
Not open for further replies.

fortage

MIS
Jun 15, 2000
329
US
The WshShell.RegDelete method does not delete keys with subkeys. Is there another method that will or some code that can assist me in doing so.

Thanks
 
I haven't tested this, but the example below taken from the Windows Script Technologies Help seems to imply that it DOES work:
Code:
Set Sh = CreateObject("WScript.Shell")
key =  "HKEY_CURRENT_USER\"
Sh.RegWrite key & "WSHTest\", "testkeydefault"
Sh.RegWrite key & "WSHTest\string1", "testkeystring1"
Sh.RegWrite key & "WSHTest\string2", "testkeystring2", "REG_SZ"
Sh.RegWrite key & "WSHTest\string3", "testkeystring3", "REG_EXPAND_SZ"
Sh.RegWrite key & "WSHTest\int", 123, "REG_DWORD"
WScript.Echo Sh.RegRead(key & "WSHTest\")
WScript.Echo Sh.RegRead(key & "WSHTest\string1")
WScript.Echo Sh.RegRead(key & "WSHTest\string2")
WScript.Echo Sh.RegRead(key & "WSHTest\string3")
WScript.Echo Sh.RegRead(key & "WSHTest\int")
Sh.RegDelete key & "WSHTest\"
Sorry about the line-wraps.
 
Oops! That may not be what you were looking for. I suppose you were thinking of an example of a key like:

"HKEY_CURRENT_USER\Something\WSHTest\"

And then deleting:

"HKEY_CURRENT_USER\Something\"

I'll take your word for it that this doesn't work, but I don't see a way to traverse the key deleting stuff either.
 
Paste the following in a .VBS and execute it to demonstrate it does delete subkeys.

Set oShell = CreateObject("WScript.Shell")
oShell.RegWrite "HKCU\Jon\",""
oShell.RegWrite "HKCU\Jon\Jon2\",""
oShell.RegWrite "HKCU\Jon\Jon2\Test","Test"
WScript.Echo "Click OK to discard"
oShell.RegDelete "HKCU\Jon\" Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top