Skip to content
June 3, 2008 / windperson

A simple JScript execute another program.

usage: script_name program_name


var WshShell = new ActiveXObject("WScript.Shell");
var objArgs = WScript.Arguments.Unnamed;
if(objArgs.length != 0)
{
    WScript.Echo("will run " + objArgs(0));
    var ReturnValue = WshShell.Run(objArgs(0), 10, true);
    WScript.Echo("run the argument program returns: " + ReturnValue);
}
else
{
    WScript.Echo("usage: " + WScript.ScriptName + " program_name");
}


p.s. save the above code using the extension name as ".js" , it only runs on MSFT Windows environment with Windows Script Host installed.
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: