Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

botatun (Programmer)
4 May 06 13:45
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';

  window.open(url, WindowName, WindowOptions);
    or
  document.location.href=url;

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?


mbrooks (Programmer)
4 May 06 13:50
No.. Due to the browser security settings you are unable to access or execute items within your filesystem.

M. Brooks
http://mbrooks.info

theniteowl (Programmer)
4 May 06 14:02
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.

botatun (Programmer)
4 May 06 14:25
"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.
theniteowl (Programmer)
4 May 06 14:42
Actually, I just put together a sample in Javascript.

CODE

<html>
<head>
<script type="text/javascript">
function runApp(which) {
  WshShell = new ActiveXObject("WScript.Shell");
  WshShell.Run (which,1,true);
}
</script>
</head>
<body>
<!-- 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>
<br>
<!-- Or use <a> descriptor -->
<a href="runApp('file://c:/test.bat');">Batch File</a>
</body>
</html>

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

botatun (Programmer)
4 May 06 16:02
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?
theniteowl (Programmer)
4 May 06 17:08
Change true to false in this line:

CODE

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.

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!

Back To Forum

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