最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to run a batch file through javascript - Stack Overflow

programmeradmin3浏览0评论

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

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

Share Improve this question asked Oct 15, 2009 at 9:52 praveenjayapalpraveenjayapal 38.6k31 gold badges74 silver badges74 bronze badges
Add a ment  | 

6 Answers 6

Reset to default 1

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() mand 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 panies (usually dealing in shared servers) disabling exec() to protect their other customers.

发布评论

评论列表(0)

  1. 暂无评论