
// This script simply tries to start the program that is the first 
// argument.

function main() 
{
    var args = WScript.Arguments;
    if ( args.length < 1 )
    {
        WScript.Echo("Usage: StartProcess.js program_path");
        return;
    }
    
    var app = "\"" + args(0) + "\"";
	var currentArgIndex = 1;
	while (currentArgIndex < args.Length)
	{
		app = app + " " + args(currentArgIndex);
		currentArgIndex++;
	}
    startProcess(app);
}

function startProcess(program) 
{
        var sh = new ActiveXObject("WScript.Shell");
        
        try
        {
            program = sh.ExpandEnvironmentStrings(program);
            WScript.Echo("Starting program: " + program);
            var exec = sh.Exec(program);
            
            // DON'T wait.  Just let cscript.exe exit.
            //while(exec.Status == 0)
            //    WScript.Sleep(30000); // 30 sec
        }
        catch(ex)
        {
            WScript.Echo("Exception running program: " + program);
            WScript.Echo(ex.message);
        }
}

main();
