Shoutbox

RegDeleteTree - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: RegDeleteTree (/showthread.php?tid=84444)

RegDeleteTree by Suxsem on 06-21-2008 at 02:41 PM

Hi!
if I use Shell.RegDeleteTree function script return an error...
if I use Shell.RegDelete function I can't delete e subkey of a key...
how can I do?
Thank, bye!


RE: RegDeleteTree by Matti on 06-21-2008 at 06:34 PM

You can use SHDeleteKey from the shlwapi library:

code:
// Registry key locations
var HKEY_CLASSES_ROOT = 0x80000000;
var HKEY_CURRENT_USER = 0x80000001;
var HKCU = HKEY_CURRENT_USER;
var HKEY_LOCAL_MACHINE = 0x80000002;
var HKEY_USERS = 0x80000003;

/**
* Registry_DeleteTree
* lKeyLocation: One of the HKEY_* constants, such as HKEY_CURRENT_USER
* sKey: Path of the key to delete
*/
function Registry_DeleteTree(lKeyLocation, sKey){
   return Interop.Call('shlwapi.dll', 'SHDeleteKeyW', lKeyLocation, sKey) === 0;
}

//EXAMPLE
var RegistryPath = MsgPlus.ScriptRegPath.substr(5); //Remove "HKCU\" prefix
Registry_DeleteTree(HKEY_CURRENT_USER, RegistryPath + "\\KeyToDelete");
For more information about this function, go to the MSDN page of SHDeleteKey.
RE: RegDeleteTree by CookieRevised on 06-21-2008 at 06:46 PM

quote:
Originally posted by Suxsem
if I use Shell.RegDeleteTree function script return an error...
Because there is no such function or method.
The three existing function methods are:
    WshShell.RegDelete
    WshShell.RegWrite
    WshShell.RegRead

quote:
Originally posted by Suxsem
if I use Shell.RegDelete function I can't delete e subkey of a key...
how can I do?
Yes you can. But that subkey must be empty; it can not contain other subkeys. You must remove the lowest subkey first and working your way up the tree, if you want to keep on using those build-in registry object functions.

Also, specify a key-name by ending the string with a final backslash and leave the final backslash off to specify a value-name.

eg:
this will remove the value 'MindReader':
WshShell.RegDelete("HKCU\\Software\\ACME\\FortuneTeller\\MindReader");

this will remove the key 'FortuneTeller':
WshShell.RegDelete("HKCU\\Software\\ACME\\FortuneTeller\\");

All this is also explained in the Windows Scripting documentation which you can download from the Official Script Database.

-------

Otherwise, use the Windows API directly like Matikke showed.

;)
RE: RegDeleteTree by Suxsem on 06-23-2008 at 11:15 AM

Thank Mattike!!!