praveenjayapal
praveenjayapal

Reputation: 38529

How to run a batch file through javascript

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

Upvotes: 0

Views: 13956

Answers (6)

ghostWarz
ghostWarz

Reputation: 11

Add the path to your batch file (i.e. C:\BAT_Files*) to your trusted sites in internet explorer. This will also modify the trusted sites used by Firefox and Google Chrome so you don't get the warnings on them either. The key is to use internet explorer's trusted site method.

Upvotes: 1

n00dle
n00dle

Reputation: 6043

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.

Upvotes: 0

KB22
KB22

Reputation: 6969

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.

Upvotes: 0

Kyle Rosendo
Kyle Rosendo

Reputation: 25277

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.

Upvotes: 1

rahul
rahul

Reputation: 187020

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

Run Method (Windows Script Host)

Upvotes: 0

Chathuranga Chandrasekara
Chathuranga Chandrasekara

Reputation: 20906

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

Tek-tips discussion on this

Upvotes: 0

Related Questions