2020-06-28 14:22:57 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Registry API
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2020-07-20 18:57:53 +00:00
|
|
|
|
2020-07-21 06:14:14 +00:00
|
|
|
var SHELL = require("lib/shell");
|
|
|
|
|
2020-06-28 14:22:57 +00:00
|
|
|
// http://apidock.com/ruby/Win32/Registry/Constants
|
2023-10-30 10:51:48 +00:00
|
|
|
var HKCR = 0x80000000;
|
|
|
|
var HKCU = 0x80000001;
|
|
|
|
var HKLM = 0x80000002;
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2023-10-30 10:51:48 +00:00
|
|
|
var STRING = 0;
|
|
|
|
var BINARY = 1;
|
|
|
|
var DWORD = 2;
|
|
|
|
var QWORD = 3;
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2023-10-30 10:51:48 +00:00
|
|
|
function getProvider(computer) {
|
2020-06-28 14:22:57 +00:00
|
|
|
var computer = (typeof(computer) !== "undefined") ? computer : ".";
|
|
|
|
var reg = GetObject("winmgmts:\\\\" + computer + "\\root\\default:StdRegProv");
|
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
2023-10-30 10:51:48 +00:00
|
|
|
function write(hKey, path, key, value, valType, computer) {
|
|
|
|
var reg = getProvider(computer);
|
2020-06-28 14:22:57 +00:00
|
|
|
|
|
|
|
reg.CreateKey(hKey, path);
|
|
|
|
|
2023-10-30 10:51:48 +00:00
|
|
|
if (valType == STRING)
|
2020-06-28 14:22:57 +00:00
|
|
|
reg.SetStringValue(hKey, path, key, value);
|
2023-10-30 10:51:48 +00:00
|
|
|
else if (valType == DWORD)
|
2020-06-28 14:22:57 +00:00
|
|
|
reg.SetDWORDValue(hKey, path, key, value);
|
2023-10-30 10:51:48 +00:00
|
|
|
else if (valType == QWORD)
|
2020-06-28 14:22:57 +00:00
|
|
|
reg.SetQWORDValue(hKey, path, key, value);
|
2023-10-30 10:51:48 +00:00
|
|
|
else if (valType == BINARY)
|
2020-06-28 14:22:57 +00:00
|
|
|
reg.SetBinaryValue(hKey, path, key, value);
|
|
|
|
}
|
|
|
|
|
2023-10-30 10:51:48 +00:00
|
|
|
function read(hKey, path, key, valType, computer) {
|
|
|
|
/*
|
|
|
|
var reg = getProvider(computer);
|
2020-06-28 14:22:57 +00:00
|
|
|
|
|
|
|
var methodName = "";
|
2023-10-30 10:51:48 +00:00
|
|
|
if (valType == STRING)
|
2020-06-28 14:22:57 +00:00
|
|
|
methodName = "GetStringValue";
|
2023-10-30 10:51:48 +00:00
|
|
|
else if (valType == DWORD)
|
2020-06-28 14:22:57 +00:00
|
|
|
methodName = "GetDWORDValue";
|
2023-10-30 10:51:48 +00:00
|
|
|
else if (valType == QWORD)
|
2020-06-28 14:22:57 +00:00
|
|
|
methodName = "GetQWORDValue";
|
2023-10-30 10:51:48 +00:00
|
|
|
else if (valType == BINARY)
|
2020-06-28 14:22:57 +00:00
|
|
|
methodName = "GetBinaryValue";
|
|
|
|
|
|
|
|
if (methodName == "")
|
2023-10-30 10:51:48 +00:00
|
|
|
return;
|
2020-06-28 14:22:57 +00:00
|
|
|
|
|
|
|
var method = reg.Methods_.Item(methodName);
|
|
|
|
var inparams = method.InParameters.SpawnInstance_();
|
|
|
|
|
|
|
|
inparams.hDefKey = hKey;
|
|
|
|
inparams.sSubKeyName = path;
|
|
|
|
inparams.sValueName = key;
|
|
|
|
|
2023-10-30 10:51:48 +00:00
|
|
|
console.log(method.Name);
|
|
|
|
console.log(JSON.stringify(inparams));
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2023-10-30 10:51:48 +00:00
|
|
|
var outparams = reg.ExecMethod_(method.Name, inparams);
|
2020-06-28 14:22:57 +00:00
|
|
|
return outparams;
|
2023-10-30 10:51:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// using IPC to read registry value
|
|
|
|
var SHELL = require("lib/shell");
|
|
|
|
var result = '';
|
|
|
|
|
|
|
|
var hKeyStr = '';
|
|
|
|
if (hKey == HKCR)
|
|
|
|
hKeyStr = "HKCR";
|
|
|
|
else if (hKey == HKCU)
|
|
|
|
hKeyStr = "HKCU";
|
|
|
|
else if (hKey == "HKLM")
|
|
|
|
hKeyStr = "HKLM";
|
|
|
|
|
|
|
|
if (hKeyStr != '') {
|
|
|
|
result = (function(s) {
|
|
|
|
s = s.substring(s.indexOf("REG_") + 4);
|
|
|
|
s = s.substring(s.indexOf(' '));
|
|
|
|
s = s.trim();
|
|
|
|
return s;
|
|
|
|
})(splitLn(SHELL.exec("reg query " + hKeyStr + "\\" + path))[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2020-06-28 14:22:57 +00:00
|
|
|
}
|
|
|
|
|
2023-10-30 10:51:48 +00:00
|
|
|
function destroy(hKey, path, key, computer) {
|
|
|
|
var reg = getProvider(computer);
|
2020-06-28 14:22:57 +00:00
|
|
|
var loc = (key == "") ? path : path + "\\" + key;
|
|
|
|
return reg.DeleteKey(hKey, loc);
|
|
|
|
}
|
|
|
|
|
2020-07-21 06:14:14 +00:00
|
|
|
/*
|
2020-06-28 14:22:57 +00:00
|
|
|
// DEPRECATED
|
2023-10-30 10:51:48 +00:00
|
|
|
function create(hiveKey, path, key, computer) {
|
2020-07-03 09:15:23 +00:00
|
|
|
console.log("Warning! Registry.create method is DEPRECATED.");
|
|
|
|
|
2020-06-28 14:22:57 +00:00
|
|
|
var computer = (typeof(computer) !== "undefined") ? computer : ".";
|
|
|
|
var sw = new ActiveXObject("WbemScripting.SWbemLocator");
|
|
|
|
var root = sw.ConnectServer(computer, "root\\default");
|
|
|
|
var reg = root.get("StdRegProv");
|
|
|
|
|
|
|
|
var enumKey = reg.Methods_.Item("EnumKey");
|
|
|
|
|
|
|
|
var inParams = enumKey.InParameters.SpawnInstance_();
|
|
|
|
inParams.hDefKey = hiveKey;
|
|
|
|
inParams.sSubKeyName = path;
|
|
|
|
|
|
|
|
var outParam = reg.ExecMethod_(enumKey.Name, inParams);
|
|
|
|
|
|
|
|
if (outParam.ReturnValue != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (outParam.sNames)
|
|
|
|
{
|
|
|
|
var subKeys = outParam.sNames.toArray();
|
|
|
|
|
|
|
|
for (var i = 0; i < subKeys.length; ++i)
|
|
|
|
{
|
|
|
|
if (subkeys[i].toUpperCase() == key.toUpperCase())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var createKey = reg.Methods_.Item("CreateKey");
|
|
|
|
var createArgs = createKey.InParameters.SpawnInstance_();
|
|
|
|
createArgs.hDefKey = hiveKey;
|
|
|
|
createArgs.sSubKeyName = path + "\\" + key;
|
|
|
|
|
|
|
|
var createRet = reg.ExecMethod_(createKey.Name, createArgs);
|
|
|
|
return createRet.returnValue == 0;
|
|
|
|
}
|
2020-07-21 06:14:14 +00:00
|
|
|
*/
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2023-10-30 10:51:48 +00:00
|
|
|
function execFile(FN) {
|
2021-12-09 07:48:53 +00:00
|
|
|
return SHELL.exec(["reg", "import", FN].join(' '));
|
2023-10-30 10:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.getProvider = getProvider;
|
|
|
|
exports.write = write;
|
|
|
|
exports.read = read;
|
|
|
|
exports.destroy = destroy;
|
|
|
|
//exports.create = create; // DEPRECATED
|
|
|
|
exports.execFile = execFile;
|
|
|
|
|
|
|
|
exports.HKCR = HKCR;
|
|
|
|
exports.HKCU = HKCU;
|
|
|
|
exports.HKLM = HKLM;
|
|
|
|
|
|
|
|
exports.STRING = STRING;
|
|
|
|
exports.BINARY = BINARY;
|
|
|
|
exports.DWORD = DWORD;
|
|
|
|
exports.QWORD = QWORD;
|
|
|
|
|
|
|
|
exports.VERSIONINFO = "Registry Module (registry.js) version 0.2.1";
|
|
|
|
exports.global = global;
|
|
|
|
exports.require = global.require;
|