-4

I want to write JS code to download and execute .exe/bat file automatically from my web server when a person clicks on the "Download" button. This is to help my customers who don't have knowledge about running programs.

Thanks in advance.

Quidam
  • 245
  • 1
  • 15
  • You can not execute files in the client device using JavaScript. – Mohamed Abbas May 20 '17 at 09:48
  • ok Is there any way to execute files on the client device? – Acros Khan May 20 '17 at 09:50
  • 1
    so, you're asking **how do I create malware** – Jaromanda X May 20 '17 at 09:55
  • 1
    `Is there any way to execute files on the client device?` - yes. step one, sit in front of the client device ... – Jaromanda X May 20 '17 at 09:57
  • @JaromandaX nope its not malware, it's for helping my clients to download our programs easily. – Acros Khan May 20 '17 at 10:10
  • yes, but can you see how if that were possible, it would also be a very simple attack vector for less scrupulous coders - in fact, slow children who don't know anything at all about computers and programming could write malware if what you want was possible – Jaromanda X May 20 '17 at 10:12
  • if your *customers* don't know how to do such a simple thing as running a program they elected to download, perhaps they have a 5 year old child or grandchild or nephew or niece that could show them how to do this – Jaromanda X May 20 '17 at 10:14
  • Are you looking for http://stackoverflow.com/questions/42906786/what-does-the-following-code-snippet-do-javascript ;) – le_m May 20 '17 at 10:51

1 Answers1

1

It's not possible. If it was possible JavaScript would have been banned everywhere, or every computer in the world would be infected with very dangerous virus.

What you ask, is basically "how to write a malware". Even if you don't have bad intentions, the malware is defined by the fact to make an action (potentially dangerous or for ads purposes) on the computer of the victim, and the victim being not aware.

So to allow users to use the Internet, it has been decided to consider legit only the code that let the user chose when the person wants to download = It needs a button or a link, and a confirmation message.

And then, when you download, you need to choose whether you want to execute the code now, with another click + confirmation message.

So it's 2 different actions.

What kind of actions do you want to do on the client side?
If you want to execute an action on a website, you don't need to make the client download your script.
It's especially dangerous, as you can imagine that the download script has the power to run itself whenever it wants, according to what you request here.

If the person can click on a download link, this same person can also click on the "execute" button, so I don't see the point to have a button to download and execute at the same time.

See also here.

Community
  • 1
  • 1
Quidam
  • 245
  • 1
  • 15