Last active
December 5, 2020 15:46
-
-
Save hironaeee/ecd65760b74ebb65f3491dbbb1dc5122 to your computer and use it in GitHub Desktop.
Add .exe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "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