Skip to content

Instantly share code, notes, and snippets.

@sstur
Created January 8, 2013 09:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sstur/4482361 to your computer and use it in GitHub Desktop.
Save sstur/4482361 to your computer and use it in GitHub Desktop.
Ensure a JS script runs in CScript on Windows
/*global WScript */
(function(ws) {
if (ws.fullName.slice(-12).toLowerCase() !== '\\cscript.exe') {
var cmd = 'cscript.exe //nologo "' + ws.scriptFullName + '"';
var args = ws.arguments;
for (var i = 0, len = args.length; i < len; i++) {
var arg = args(i);
cmd += ' ' + (~arg.indexOf(' ') ? '"' + arg + '"' : arg);
}
new ActiveXObject('WScript.Shell').run(cmd);
ws.quit();
}
})(WScript);
WScript.echo('We are now in CScript. Press Enter to Quit...');
WScript.stdIn.readLine();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment