mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 06:54:58 +00:00
Update powershell.js
This commit is contained in:
parent
f5833dd103
commit
aed2ab6e04
|
@ -4,33 +4,38 @@
|
|||
|
||||
var SHELL = require("lib/shell");
|
||||
|
||||
function PowershellInterface() {
|
||||
var PowershellObject = function() {
|
||||
this.execType = "ps1";
|
||||
this.dataType = -1;
|
||||
this.target = null;
|
||||
|
||||
this.setExecType = function(execType) {
|
||||
this.execType = execType;
|
||||
return this;
|
||||
};
|
||||
|
||||
this.load = function(script) {
|
||||
this.target = script;
|
||||
this.dataType = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
this.loadCommand = function(command) {
|
||||
this.target = command;
|
||||
this.dataType = 1;
|
||||
return this;
|
||||
};
|
||||
|
||||
this.loadFile = function(filename) {
|
||||
this.target = filename;
|
||||
this.dataType = 2;
|
||||
return this;
|
||||
};
|
||||
|
||||
this.loadUrl = function(url) {
|
||||
this.target = url;
|
||||
this.dataType = 3;
|
||||
return this;
|
||||
};
|
||||
|
||||
// For example:
|
||||
|
@ -60,6 +65,7 @@ function PowershellInterface() {
|
|||
default:
|
||||
console.error("Invalid scheme");
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
this.exec = function(args) {
|
||||
|
@ -79,7 +85,8 @@ function PowershellInterface() {
|
|||
];
|
||||
|
||||
switch (this.dataType) {
|
||||
case 3: // dataType: URL(3)
|
||||
case 3: // dataType: URL(3)\
|
||||
// todo
|
||||
break;
|
||||
|
||||
case 2: // dataType: file(2)
|
||||
|
@ -90,9 +97,9 @@ function PowershellInterface() {
|
|||
case 1: // dataType: command(1)
|
||||
cmd.push("-Command");
|
||||
if (typeof this.target === "string") {
|
||||
cmd.push("& {" + cmd + "}");
|
||||
cmd.push("& {" + this.target + "}");
|
||||
} else {
|
||||
cmd.push("& {" + SHELL.build(cmd) + "}");
|
||||
cmd.push("& {" + SHELL.build(this.target) + "}");
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -114,24 +121,24 @@ function PowershellInterface() {
|
|||
this.runAs = function() {
|
||||
if (this.execType != "ps1") {
|
||||
console.warn("The execType is not set 'ps1'. Will be forward it to the default shell.");
|
||||
return execCommand("Start-Process cmd \"/q /c " + SHELL.addslashes(SHELL.build(this.target)) + "\" -Verb RunAs");
|
||||
return this.exec("Start-Process cmd \"/q /c " + SHELL.addslashes(SHELL.build(this.target)) + "\" -Verb RunAs");
|
||||
} else {
|
||||
return execCommand("Start-Process cmd \"/q /c " + SHELL.addslashes(SHELL.build(cmd)) + "\" -Verb RunAs");
|
||||
return this.exec("Start-Process cmd \"/q /c " + SHELL.addslashes(SHELL.build(cmd)) + "\" -Verb RunAs");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function execScript(scriptName, args) {
|
||||
return (new PowershellInterface()).loadFile(scriptName).exec(args);
|
||||
return (new PowershellObject()).loadFile(scriptName).exec(args);
|
||||
};
|
||||
|
||||
function execCommand(cmd) {
|
||||
return (new PowershellInterface()).loadCommand(cmd).exec();
|
||||
return (new PowershellObject()).loadCommand(cmd).exec();
|
||||
};
|
||||
|
||||
function runAs(cmd) {
|
||||
return (new PowershellInterface()).setExecType("cmd").runAs();
|
||||
return (new PowershellObject()).setExecType("cmd").runAs();
|
||||
};
|
||||
|
||||
exports.execScript = execScript;
|
||||
|
|
Loading…
Reference in New Issue
Block a user