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.
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.
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.