What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » HELP - Controlling other scripts!

HELP - Controlling other scripts!
Author: Message:
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: HELP - Controlling other scripts!
I wont quote your post it will just make it too long.


Question #1:
Vista has an api function called RegDeleteTree which will recursively delete a folder in the registry. However this is not available on Windows XP. In order for this to work on Windows XP you need to enumerate the subkeys and recursively delete them.

js code:
var HKEY_CLASSES_ROOT = 0x80000000;
var HKEY_CURRENT_USER = 0x80000001;
var HKEY_LOCAL_MACHINE = 0x80000002;
var HKEY_USERS = 0x80000003;

var KEY_READ = 0x20019;
var KEY_WRITE = 0x20006;
var KEY_EXECUTE = 0x20019;
var KEY_ALL_ACCESS = 0xf003f;
var REG_OPTION_NON_VOLATILE = 0;
var ERROR_SUCCESS = 0;
var ERROR_NO_MORE_ITEMS = 259;

function RegDeleteTree(lKeyLocation, lpSubKey) {
    if ( IsWinVista() === true ) {
        return Interop.Call('advapi32', 'RegDeleteTreeW', lKeyLocation, lpSubKey) === ERROR_SUCCESS;
    } else {
        var oKeys = Registry_EnumSubKeys(lKeyLocation, lpSubKey);
        for ( var oKey in oKeys ) {
            Registry_DeleteKeyValue(lKeyLocation, sKey, oKeys[oKey]);
        }
        oKeys = Registry_EnumKeys(lKeyLocation, lpSubKey);
        for ( var oKey in oKeys ) {
            RegDeleteTree(lKeyLocation, sKey+'\\'+oKeys[oKey]);
            Registry_DeleteKey(lKeyLocation, sKey+'\\'+oKeys[oKey]);
        }
    }
}

function Registry_DeleteKey(lKeyLocation, sKey){
    var hKey = Interop.Allocate(4);
    return Interop.Call('advapi32.dll', 'RegDeleteKeyW', lKeyLocation, sKey) === ERROR_SUCCESS;
}

function Registry_DeleteKeyValue(lKeyLocation, sKey, sKeyName){
    var hKey = Interop.Allocate(4);
    var lRetVal = Interop.Call('advapi32.dll', 'RegOpenKeyExW', lKeyLocation, sKey, 0, KEY_WRITE, hKey)
    if (lRetVal === ERROR_SUCCESS) {
        lRetVal = Interop.Call('advapi32.dll', 'RegDeleteValueW', hKey.ReadDWORD(0), sKeyName);
        Registry_CloseKey(hKey.ReadDWORD(0));
        return lRetVal === ERROR_SUCCESS;
    }else{ return false; }
   
}

function Registry_EnumSubkeys(lKeyLocation, sKey, sOut){
    var hKey = Interop.Allocate(4);
    var lpName = Interop.Allocate((255+1) * 2);
    var lpcName = Interop.Allocate(4);
        lpcName.WriteDWORD(0, 255);
    var lpftLastWriteTime = Interop.Allocate(8);
    var lIndex = 0;
   
    var lRetVal = Interop.Call('advapi32.dll', 'RegOpenKeyExW', lKeyLocation, sKey, 0, KEY_READ, hKey);
    if (lRetVal === ERROR_SUCCESS){
        while (Interop.Call('advapi32', 'RegEnumKeyExW', hKey.ReadDWORD(0), lIndex, lpName, lpcName, 0, 0, 0, 0) != ERROR_NO_MORE_ITEMS){
            sOut.push(lpName.ReadString(0));
            lIndex++;
            lpcName.WriteDWORD(0, 255);
            lpName.Size = 0;
            lpName = Interop.Allocate(512);
        }
        Registry_CloseKey(hKey.ReadDWORD(0));
        return sOut;
    } else { return false; }
}

function Registry_EnumKeys(lKeyLocation, sKey, sOut){
    var hKey = Interop.Allocate(4);
    var lpName = Interop.Allocate((255+1) * 2);
    var lpcName = Interop.Allocate(4);
        lpcName.WriteDWORD(0, 255);
    var lIndex = 0;
    var lRetVal = Interop.Call('advapi32.dll', 'RegOpenKeyExW', lKeyLocation, sKey, 0, KEY_READ, hKey);
    if (lRetVal === ERROR_SUCCESS){
        while (Interop.Call('advapi32', 'RegEnumValueW', hKey.ReadDWORD(0), lIndex, lpName, lpcName, 0, 0, 0, 0) != ERROR_NO_MORE_ITEMS){
            sOut.push(lpName.ReadString(0));
            lIndex++;
            lpcName.WriteDWORD(0, 255);
            lpName.Size = 0;
            lpName = Interop.Allocate(512);
        }
        Registry_CloseKey(hKey.ReadDWORD(0));
        return sOut;
    } else { return false; }
}

function Registry_CloseKey(hKey){
    return Interop.Call('advapi32.dll', 'RegCloseKey', hKey) === ERROR_SUCCESS;
}

function IsWinVista() { return Interop.Call('user32', 'GetVersion') % 256 === 6; }

Question #2:
There are two ways to accomplish this. The first way would be to restart Windows Live Messenger to force scripts to be enabled/disabled after changing their registry value.

This can be accomplished by doing the following:
js code:
Interop.Call('shell32', 'ShellExecuteW', 0, 'open', WSS.RegRead("HKLM\\SOFTWARE\\Patchou\\Messenger Plus! Live\\AppDir")+'\\MPTools.exe', '/restartmessenger', '', 0 /* SW_HIDE */);

Alternately you can restart ALL scripts as if one is being imported.
Note: This can cause undesired resultes
js code:
function restartScripts(){
    var nMessage = 0x81ce;
    var MsgPump_hWnd = Interop.Call('user32', 'FindWindowW', 'MessengerPlusLive_MsgPump', '');
    Interop.Call('user32', 'SendMessageW', MsgPump_hWnd, nMessage, 0, 1)
}

Question #3:
You can use the ShellExecute API function to open the folder that is stored in the registry:
js code:
Interop.Call('shell32', 'ShellExecuteW', 0, 'open', WSS.RegRead("HKLM\\SOFTWARE\\Patchou\\Messenger Plus! Live\\ScriptsDir"), '', '', 5 /* SW_SHOW */)
07-14-2009 01:22 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
HELP - Controlling other scripts! - by whiz on 07-14-2009 at 12:41 PM
RE: HELP - Controlling other scripts! - by matty on 07-14-2009 at 01:22 PM
RE: HELP - Controlling other scripts! - by whiz on 07-16-2009 at 08:44 AM
RE: HELP - Controlling other scripts! - by matty on 07-16-2009 at 12:46 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On