whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
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
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; } <<<
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.
|
|