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:
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. HELP - Controlling other scripts!
Javascript code:
var WSS = new ActiveXObject("WScript.Shell");
WSS.RegDelete(MsgPlus.ScriptRegPath + "\\...");

1) This can delete a key, but not a folder.  Is is possible to remove a folder?

Javascript code:
var Name = "Script Name";
var Enabled = 0;
WSS.RegWrite("HKCU\\SOFTWARE\\Patchou\\Messenger Plus! Live\\GlobalSettings\\Scripts\\" + Name + "\\Enabled", Enabled.toString(16));

2) This does uncheck the script in the Messenger Plus! options, but it does not actually disable the script.  Is it possible to stop a script with another method?

Javascript code:
WSS.RegRead("HKLM\\SOFTWARE\\Patchou\\Messenger Plus! Live\\ScriptsDir");

3) Is that right?  Can that be used to open the folder in Windows Explorer?
07-14-2009 12:41 PM
Profile E-Mail PM Find Quote Report
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.

Javascript 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:
Javascript 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
Javascript 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:
Javascript 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
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. RE: HELP - Controlling other scripts!
The answers to 2 and 3 are fine, but I think I found a few problems...

quote:
Originally posted by matty
Javascript 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; }



quote:
Originally posted by JavaScript Dubugger
code:
Interop.Call failed to locate function "GetVersion"
Error: unknown (code: -2147467259)
       File: [Draft].js. Line: 94.
Error: unknown (code: -2147467259)
       File: [Draft].js. Line: 94.
Error: unknown (code: -2147467259)
       File: [Draft].js. Line: 94.


I changed the highlighted line at the bottom to return false (since I use XP), and...

quote:
Originally posted by JavaScript Dubugger
code:
Error: Object expected (code: -2146823281)
       File: [Draft].js. Line: 20.
Error: Object expected (code: -2146823281)
       File: [Draft].js. Line: 20.



The highlighted line near the middle appears to have missed a capital "K", which I changed, and...

The debugger showed no errors, but no keys or folders were removed.
07-16-2009 08:44 AM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: HELP - Controlling other scripts!
quote:
Originally posted by matty
Javascript code:
function IsWinVista() { return Interop.Call('user32', 'GetVersion') % 256 === 6; };



Javascript code:
function IsWinVista() { return Interop.Call('kernel32', 'GetVersion') % 256 === 6; };


Oops!

As for the recursive registry deleting I will have to see when I get home at some point.
07-16-2009 12:46 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


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