welsonjs/lib/winlibs.js

117 lines
2.9 KiB
JavaScript
Raw Normal View History

2020-07-25 20:33:42 +00:00
////////////////////////////////////////////////////////////////////////
// Windows Library API
////////////////////////////////////////////////////////////////////////
2020-07-26 09:18:18 +00:00
2020-07-25 20:33:42 +00:00
var SHELL = require("lib/shell");
var FILE = require("lib/file");
2020-07-25 20:33:42 +00:00
2020-07-29 05:51:39 +00:00
/**
* @param {string} LIB
* @return {string} clsid
*/
exports.createManifest = function(FN, clsid) {
var manifestPath = FN + ".manifest";
if (typeof(clsid) !== "undefined") {
clsid = "4B72FC46-C543-4101-80DB-7777848DACDC";
}
var lines = [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>",
"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">",
"<file name=\"" + FN + ".dll\">",
"<comClass clsid=\"{" + clsid + "}\" threadingModel=\"Apartment\" progid=\"" + FN + "\" />",
"</file>",
"</assembly>"
];
// write a manifest file
FILE.writeFile(manifestPath, lines.join("\r\n"), FILE.CdoCharset.CdoUTF_8);
2020-07-29 05:51:39 +00:00
return FILE.fileExists(manifestPath);
};
/**
* @param {string} LIB
* @return {function}
*/
2020-07-25 20:33:42 +00:00
exports.loadLibrary = function(LIB) {
var dllManifest = LIB + ".manifest";
if (FILE.fileExists(dllManifest)) {
var actCtx = CreateObject("Microsoft.Windows.ActCtx");
actCtx.Manifest = dllManifest;
try {
var DX = actCtx.CreateObject("MessageBox");
return {
call: function(FN, args) {
return DX[FN].call(this, args);
}
2020-07-26 09:30:12 +00:00
}
} catch(e) {
// return null;
2020-07-25 20:33:42 +00:00
}
} else {
return {
call: function(FN, args) {
var cmd = [
"rundll32.exe"
];
if (typeof(FN) === "undefined") {
FN = "DllMain";
}
cmd.push(LIB + ".dll," + FN);
if (typeof(args) !== "undefined") {
cmd = cmd.concat(args);
}
return SHELL.exec(cmd);
}
};
}
2020-07-25 20:33:42 +00:00
};
2020-07-25 20:46:25 +00:00
/**
*/
exports.SHELL32 = exports.loadLibrary("SHELL32");
2020-07-26 09:09:28 +00:00
/**
* @param {string} name
* @param {Object} applets
* @param {Array} applets
* @return {string}
*/
2020-07-26 09:03:17 +00:00
exports.showControlPanel = function(name, applets, args) {
2020-07-25 20:56:14 +00:00
var _applets = [];
2020-07-25 20:46:25 +00:00
var _args = [];
2020-07-25 20:56:14 +00:00
// write a applets section
_applets.push(name + ".cpl");
if (typeof(applets) !== "undefined") {
for (var i in applets) {
_applets.push(applets[i]);
2020-07-25 20:46:25 +00:00
}
}
2020-07-25 20:56:14 +00:00
// write a args section
_args.push(_applets.join(','));
// run command
2020-07-26 09:09:28 +00:00
return exports.SHELL32.call("Control_runDLL", _args);
2020-07-25 20:46:25 +00:00
};
/**
*/
2020-07-26 09:03:17 +00:00
exports.showNetworkAdapters = function() {
2020-07-25 20:58:15 +00:00
return exports.openControlPanel("ncpa", ["@0", 3]);
2020-07-25 20:46:25 +00:00
};
2020-07-26 09:09:28 +00:00
/**
*/
2020-11-13 09:47:03 +00:00
exports.showEULA = function() {
2020-07-26 09:09:28 +00:00
return exports.SHELL32.call("ShellAboutW");
};
exports.VERSIONINFO = "Windows Lib (winlibs.js) version 0.1.1";
exports.global = global;
exports.require = global.require;