welsonjs/lib/powershell.js

44 lines
1.0 KiB
JavaScript
Raw Normal View History

////////////////////////////////////////////////////////////////////////
// Powershell API
///////////////////////////////////////////////////////////////////////
2020-07-18 20:02:49 +00:00
var SHELL = require("lib/shell");
exports.VERSIONINFO = "Powershell (powershell.js) version 0.1";
exports.global = global;
exports.require = global.require;
2020-07-18 20:02:49 +00:00
exports.execScript = function(scriptName, args) {
2020-07-26 11:40:25 +00:00
var cmd = [
"powershell.exe",
"-NoProfile",
"-ExecutionPolicy",
"ByPass",
"-nologo",
"-file",
scriptName + ".ps1"
];
if (typeof(cmd) !== "undefined") {
cmd = cmd.concat(args);
2020-07-18 20:51:23 +00:00
}
2020-07-26 11:40:25 +00:00
return SHELL.exec(cmd);
2020-07-18 20:02:49 +00:00
};
2020-07-26 11:40:25 +00:00
exports.execCommand = function(cmd) {
return SHELL.exec([
"powershell.exe",
"-NoProfile",
"-ExecutionPolicy",
"ByPass",
"-nologo",
"-Command",
"& {" + cmd + "}"
]);
2020-07-18 21:06:41 +00:00
};
2020-08-04 09:29:42 +00:00
exports.runAs = function(cmd) {
2020-08-04 10:38:21 +00:00
return exports.execCommand("Start-Process cmd \"/q /c " + SHELL.addslashes(SHELL.makeCmdLine(cmd)) + "\" -Verb RunAs");
2020-08-04 09:29:42 +00:00
};