Skip to content

Instantly share code, notes, and snippets.

@hironaeee
Last active December 5, 2020 15:46
Show Gist options
  • Select an option

  • Save hironaeee/ecd65760b74ebb65f3491dbbb1dc5122 to your computer and use it in GitHub Desktop.

Select an option

Save hironaeee/ecd65760b74ebb65f3491dbbb1dc5122 to your computer and use it in GitHub Desktop.
Add .exe
"use strict";
// Objects
wsh = WScript.createObject("WScript.Shell");
// Variables
var shellPath, opt, arg;
var extension;
arg = WScript.Arguments.Item(0);
extension = arg.split(".").slice(-1);
// Command Prompt, Powershell or exe file (try to judge with extension)
if (extension == "bat") {
shellPath = "C:/Windows/System32/cmd.exe";
opt = " /c ";
} else if (extension == "ps1") {
shellPath = "C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe";
opt = " -File ";
} else if (extension == "exe") {
shellPath = "";
opt = "";
} else {
WScript.Echo("Error!!! No expected extension");
WScript.Quit(1);
}
var cmd = shellPath + opt + arg;
//retCode = wsh.Run(cmd, 1, true); // debug
var retCode = wsh.Run(cmd, 0, true);
WScript.Quit(retCode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment