Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Run Batch file by javascript.

Run Batch file by javascript.

This .bat file will run script to send bunch of files to AS400.

 var url = "C:/ECommerce/CpyOrder.bat"
 var WindowName = 'Run_File';
 var WindowOptions =
     'width=400,height=200, left=180,top=80, toolbar=no, location=no, directories=no, status=yes, scrollbars=yes,resize=no,menubar=no';, WindowName, WindowOptions);

When I tried to open new window it said "Accessed is denied"
When I try open document in same window it said "Permission denied".

Is it possible to run .bat file by javascript?

RE: Run Batch file by javascript.

No.. Due to the browser security settings you are unable to access or execute items within your filesystem.

M. Brooks

RE: Run Batch file by javascript.

If you are using Internet Explorer you can do this by using ActiveX and the FileSystemObject.  It will only work in IE and executing the script will prompt the user with a security warning for the ActiveX and they will have to allow it before it happens.

If this is something you will run on your own machine then it is easier to have the file stored as a .HTA file (HTML for Applications) which is written with HTML and VBScript/JScript but executes as a client-side application with whatever rights the current logon has.

I do not have any Javascript sample code but I have some in VBScript.  Or you can do a Google search for JScript FileSystemObject which should turn up some sample code.

My assumption is that you want to add a button on your own personal web page to perform the function?

It's hard to think outside the box when I'm trapped in a cubicle.

RE: Run Batch file by javascript.

"If you are using Internet Explorer you can do this by using ActiveX and the FileSystemObject".
May you show me some example of how to do it.
Thank you.

RE: Run Batch file by javascript.

Actually, I just put together a sample in Javascript.


<script type="text/javascript">
function runApp(which) {
  WshShell = new ActiveXObject("WScript.Shell");
  WshShell.Run (which,1,true);
<!-- Two ways to create a link to run the app. -->
<font onClick="runApp('file://c:/winnt/notepad.exe');" style="cursor: hand;"><u>Notepad</u></font>
<!-- Or use <a> descriptor -->
<a href="runApp('file://c:/test.bat');">Batch File</a>

It's hard to think outside the box when I'm trapped in a cubicle.

RE: Run Batch file by javascript.

Thank you. It is work with notepad.exe, but throw "Unable to wait for process" error. Do you know how to suppress it? Also, the .bat that has FTP script only shows in seconds and disappeared?

RE: Run Batch file by javascript.

Change true to false in this line:


WshShell.Run (which,1,true);

That will stop it from giving the error when opening notepad.

As for the batch file, you have to have a bat file of that name in that location and it will only last as long as the bat file is running and the window will close automatically.
I just put a simple one line .bat file on my system to test with.

It's hard to think outside the box when I'm trapped in a cubicle.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close