Update powershell.js

This commit is contained in:
Namhyeon Go 2023-03-09 19:16:00 +09:00 committed by GitHub
parent 42f971ab07
commit 4867faab16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,14 +1,78 @@
////////////////////////////////////////////////////////////////////////
// Powershell API
// Powershell Interface API
///////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
exports.VERSIONINFO = "Powershell (powershell.js) version 0.1";
exports.global = global;
exports.require = global.require;
/*
exports.execScript = function(scriptName, args) {
// new powershell interface
function PowershellInterface() {
this.type = -1;
this.target = null;
this.load = function(script) {
this.target = script;
this.type = 0;
};
this.loadFile = function(filename) {
this.target = filename;
this.type = 1;
};
this.loadRemoteUrl = function(url) {
this.target = url;
this.type = 2;
};
// For example:
// file:C:\\a\\b\\c
// http://
// https://
// data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==
this.loadUri = function(uri) {
var pos = uri.indexOf(':');
var scheme = (pos < 0 ? '' : url.substring(0, pos));
var target = (pos < 0 ? uri : url.substring(pos + 1));
switch (scheme) {
case 'http':
case 'https':
this.loadRemoteUrl(target);
break;
case 'file':
this.load(target);
break;
}
};
this.exec = function() {
switch (this.type) {
case 2:
// todo
break;
case 1:
// todo
break;
case 0:
// todo
break;
default:
break;
}
};
}
*/
function execScript(scriptName, args) {
var cmd = [
"powershell.exe",
"-NoProfile",
@ -26,7 +90,7 @@ exports.execScript = function(scriptName, args) {
return SHELL.exec(cmd);
};
exports.execCommand = function(cmd) {
function execCommand(cmd) {
return SHELL.exec([
"powershell.exe",
"-NoProfile",
@ -38,6 +102,15 @@ exports.execCommand = function(cmd) {
]);
};
exports.runAs = function(cmd) {
return exports.execCommand("Start-Process cmd \"/q /c " + SHELL.addslashes(SHELL.makeCmdLine(cmd)) + "\" -Verb RunAs");
function runAs(cmd) {
return execCommand("Start-Process cmd \"/q /c " + SHELL.addslashes(SHELL.makeCmdLine(cmd)) + "\" -Verb RunAs");
};
exports.execScript = execScript;
exports.execCommand = execCommand;
exports.runAs = runAs;
exports.VERSIONINFO = "Powershell (powershell.js) version 0.1.1";
exports.AUTHOR = "abuse@catswords.net";
exports.global = global;
exports.require = global.require;