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-07-20 18:57:53 +00:00
|
|
|
exports.VERSIONINFO = "Registry Module (registry.js) version 0.1";
|
|
|
|
exports.global = global;
|
|
|
|
exports.require = global.require;
|
2020-06-28 14:22:57 +00:00
|
|
|
|
|
|
|
// http://apidock.com/ruby/Win32/Registry/Constants
|
2020-07-20 18:57:53 +00:00
|
|
|
exports.HKCR = 0x80000000;
|
|
|
|
exports.HKCU = 0x80000001;
|
|
|
|
exports.HKLM = 0x80000002;
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2020-07-20 18:57:53 +00:00
|
|
|
exports.STRING = 0;
|
|
|
|
exports.BINARY = 1;
|
|
|
|
exports.DWORD = 2;
|
|
|
|
exports.QWORD = 3;
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2020-07-20 18:57:53 +00:00
|
|
|
exports.provider = function(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;
|
|
|
|
}
|
|
|
|
|
2020-07-20 18:57:53 +00:00
|
|
|
exports.write = function(hKey, path, key, value, valType, computer) {
|
|
|
|
var reg = exports.provider(computer);
|
2020-06-28 14:22:57 +00:00
|
|
|
|
|
|
|
reg.CreateKey(hKey, path);
|
|
|
|
|
2020-07-20 18:57:53 +00:00
|
|
|
if (valType == exports.STRING)
|
2020-06-28 14:22:57 +00:00
|
|
|
reg.SetStringValue(hKey, path, key, value);
|
2020-07-20 18:57:53 +00:00
|
|
|
else if (valType == exports.DWORD)
|
2020-06-28 14:22:57 +00:00
|
|
|
reg.SetDWORDValue(hKey, path, key, value);
|
2020-07-20 18:57:53 +00:00
|
|
|
else if (valType == exports.QWORD)
|
2020-06-28 14:22:57 +00:00
|
|
|
reg.SetQWORDValue(hKey, path, key, value);
|
2020-07-20 18:57:53 +00:00
|
|
|
else if (valType == exports.BINARY)
|
2020-06-28 14:22:57 +00:00
|
|
|
reg.SetBinaryValue(hKey, path, key, value);
|
|
|
|
}
|
|
|
|
|
2020-07-20 18:57:53 +00:00
|
|
|
exports.read = function(hKey, path, key, valType, computer) {
|
|
|
|
var reg = exports.provider(computer);
|
2020-06-28 14:22:57 +00:00
|
|
|
|
|
|
|
var methodName = "";
|
2020-07-20 18:57:53 +00:00
|
|
|
if (valType == exports.STRING)
|
2020-06-28 14:22:57 +00:00
|
|
|
methodName = "GetStringValue";
|
2020-07-20 18:57:53 +00:00
|
|
|
else if (valType == exports.DWORD)
|
2020-06-28 14:22:57 +00:00
|
|
|
methodName = "GetDWORDValue";
|
2020-07-20 18:57:53 +00:00
|
|
|
else if (valType == exports.QWORD)
|
2020-06-28 14:22:57 +00:00
|
|
|
methodName = "GetQWORDValue";
|
2020-07-20 18:57:53 +00:00
|
|
|
else if (valType == exports.BINARY)
|
2020-06-28 14:22:57 +00:00
|
|
|
methodName = "GetBinaryValue";
|
|
|
|
|
|
|
|
if (methodName == "")
|
|
|
|
return;
|
|
|
|
|
|
|
|
var method = reg.Methods_.Item(methodName);
|
|
|
|
var inparams = method.InParameters.SpawnInstance_();
|
|
|
|
|
|
|
|
inparams.hDefKey = hKey;
|
|
|
|
inparams.sSubKeyName = path;
|
|
|
|
inparams.sValueName = key;
|
|
|
|
|
|
|
|
var outparams = reg.ExecMethod_(method.Name, inparams);
|
|
|
|
|
|
|
|
return outparams;
|
|
|
|
}
|
|
|
|
|
2020-07-20 18:57:53 +00:00
|
|
|
exports.destroy = function(hKey, path, key, computer) {
|
|
|
|
var reg = exports.provider(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
|
2020-07-20 18:57:53 +00:00
|
|
|
exports.create = function(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
|
|
|
|
2021-12-09 07:48:53 +00:00
|
|
|
exports.execFile = function(FN) {
|
|
|
|
return SHELL.exec(["reg", "import", FN].join(' '));
|
2020-07-18 21:52:13 +00:00
|
|
|
};
|