开发者

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 possi开发者_如何学Cble to bypass that warning to run.. Orelse, is there any other way to run the bat file through javascript

Thanks,

Praveen J


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.


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.


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

Tek-tips discussion on this


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

Run Method (Windows Script Host)


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜