Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a shortcut with 'target' "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js".

I want to run that from a batch file so I copied the "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js" into cmd.exe command line and pressed enter. Nothing happened.

How can I run "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js" from a command line on Windows7?


the js file contains

var WshShell = new ActiveXObject("Wscript.Shell");"java -Dlog.dir=%TEMP% -jar taf-loader.jar", 0, false);

I tried to run the js file with both Wscript.exe and Cscript.exe as @Serge suggested but nothing worked = the program I start by doubleclicking hasn't started. No error either.

C:\>Cscript.exe "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js"
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

C:\>Wscript.exe "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js"

share|improve this question
What language is the .js file written in JavaScript or JScript? – Robert Oct 17 '12 at 7:43
@Robert: I don't know. It's not my script. It's a commercial product that I want to be able to start by one click or in a very fast way (Windows7). If I pin what is running it won't start next time. – Radek Oct 17 '12 at 21:14
up vote 5 down vote accepted

You have two options:

Cscript.exe "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js"


Wscript.exe "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js"

The former one starts the command line version of Windows Scripting Host and the latter one is starting the window version.

The command line options are documented here:

and here:

In your script file you should use the full path to your jar file and possibly full path to the java.exe

Alternatively, to allow the java.exe locate the tar-loader.jar file you should change the current directory to the one containing this file, so before invoking wscript make cd "C:\Users\Public\TestPro\TestPro Automation Framework\"

As you mentioned that you like to run this script in a single touch, you also may create a shortcut on your desktop that has a command line set to Wscript.exe "C:\Users\Public\TestPro\TestPro Automation Framework\taf.js" and working directory set to C:\Users\Public\TestPro\TestPro Automation Framework\

share|improve this answer
I updated my answer. – Radek Oct 17 '12 at 5:32
@Radek Could you please tell, why do you use this script at all if you anyway start it from the batch file? why not to invoke java directly from the batch file? – Serge Oct 17 '12 at 12:05
@Radek see the edit to the answer please – Serge Oct 17 '12 at 12:07
I agree with Serge, why not run java -Dlog.dir=%TEMP% -jar taf-loader.jar from the command-line or batch directly? Why this round-about method? (Obviously, java.exe has to be in the PATH.) – Karan Oct 17 '12 at 20:22
@Karan & Serge: See my comment under my question. It is not my script. I don't want to modify it. Maybe I can use code from it to create my own batch file or something like that. I prefer not to modify anything. – Radek Oct 17 '12 at 21:15

If you can run 'java' in a console window with no errors, then

1) Create a text file on your desktop called 'taf.txt'

2) Enter "java -Dlog.dir=%TEMP% -jar taf-loader.jar" into the text file, and save it

3) Rename the file to 'taf.bat'


Using a scripting host to start a script which launches a shell that launches a java program is just too long winded.

Think of it in terms of what you want to achieve - you want the program to launch with a click of an icon.

The batch file is the fastest way to achieve that on win7.

If you were using an OS that could natively kick off a Javascript script with no messing about it would be a nice way to launch it, but that script wouldn't work on anything other than windows (unless ActiveX is ported now - been a long time since I've used it).

Source: Professional Java Developer for over 10 years

share|improve this answer

Java 1.6 comes with jrunscript to run JavaScript outside of web browsers.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .