matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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 */)
|
|