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");
WshShell.run("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"

  • 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

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: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cscript

and here: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/wscript

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\

| improve this answer | |
  • 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
  • "Maybe I can use code from it to create my own batch file or something like that." - Yeah, so what happens when you do? – Karan Oct 17 '12 at 21:18
  • It was just a though. I don't know how to do it right now and I am not sure if can cause any troubles why I start the program in such batch and it is not 100% correct. – Radek Oct 17 '12 at 21:41
  • @Radek does both tar-loader.jar reside in the same 'C:\Users\Public\TestPro\TestPro Automation Framework\' directory? – Serge Oct 17 '12 at 22:39

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

| improve this answer | |

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

| improve this answer | |
  • It's not for javascript (js) files: it's for Java scripts and (now) not included in JRE. – 0zkr PM Mar 8 '18 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.