views:

738

answers:

5

Hi Friends, I have included the bat file path in anchor tag like this

<a href='pdfs1255601585.bat'>Execute batch file</a> But its showing some security warning, before executing the bat file.. Is it possible to bypass that warning to run.. Orelse, is there any other way to run the bat file through javascript

Thanks,
Praveen J

A: 

You can't access file system using JavaScript. It is by design.

Tek-tips discussion on this

Chathuranga Chandrasekara
A: 

You can use ActiveX to do this. But it will be Internet Explorer specific.

Run Method (Windows Script Host)

rahul
is there any chance to focus without using ActiveX componenet?
praveenjayapal
A: 

You could use the code described here in order to run that batch. Bypassing the security warning - which is there with a reason - is kinda tricky. You could write an FireFox extension which would read the file to run from a particular page. Of course this extension needs to be installed with user interaction too. So no real bypassing at all...

Just for my curiousity; why do you want to do that?

ADDITION:

In php you could use the exec() command to achieve this.

KB22
Actually, i have a set of cmd line to execute-so i write those things in bat file and trying to run from here.. is there any other way through PHP.. Please guide me
praveenjayapal
pls. see the addition above
KB22
+2  A: 

Can you imagine the chaos if this were possible? Visit a page and erase your harddrive.

Although there are applications where this would be handy, by design it was decided against as the security threat is massive.

You will not be able to do this simply though the use of JavaScript.

Kyle Rozendo
A: 

You'd need some form of server-side language (such as PHP mentioned above) to do that. However generally it's considered bad practice and can open to you to any number of security risks if not undertaken carefully. Javascript can only access client-side information and files held on the server - it can't run executables (unless you include AJAX through a Server-side language running executables).

If you are intent on doing this, PHP exec() is the way to go, but you'd need to check your server configuration as I've heard of some companies (usually dealing in shared servers) disabling exec() to protect their other customers.

ianhales
ianhales: how to enable the exec() and where to do that?
praveenjayapal
You'd need to speak to your hosting provider. It may be that they allow it - who is your host? They'll probably have it in an FAQ or something if it was blocked. If not then go with the link that @KB22 posted below.
ianhales