How to run .exe on a Webpage

There are certain scenarios where you need to run your .EXE file through HTML page. In this blog I will show you how can you achieve this task on html page by using JavaScript.

<a href="javascript:LaunchApp()">Click here to Execute your file</a>

The above code will call a user-defined function LaunchApp() which you can see in the following code snippets.

<script>

 

function LaunchApp() {

 

if (!document.all) {

 

  alert ("This ActiveXObject is only available for Internet Explorer");

 

  return;

 

}

 

var ws = new ActiveXObject("WScript.Shell");

 

ws.Exec("D:\\Software\\youfile.exe");

 

}

 

</script>

 

In the above JavaScript a LaunchApp() is defined which will first check for the browser if your browser is not internet explorer  then it will show you message that your browser doesn’t support the ActiveXObject and only available for InternetExplorer,If it is InternetExplorer then it will create object for WScript.Shell and will execute yourfile.exe in the D:\software location.

Thanks for Indika Prabath for raising this issue which would definitely help others.

As there is so much demand of how the above can be implemented in firefox browser. So here it is Run .exe on a Webpage using Firefox.

Tagged: , , , , ,
  • http://www.saltrange.com ali

    what would path we will use for web server …

    e.g http://www.abc.com/video/abc.exe or else…

    • http://codereflex.net Syed Asad Ahmed

      Describe your task in detail.

      • JeremyDR

        Syed, I am able to launch an application using the code you provided but I am need to add parameters along with it. example: launch.exe /console or something similar. Any help would be appreciated.

        • SyedAsadAhmed

          If i underatand corectly your question. Yes JeremyDR you can pass parameter in the launchApp function have a look at following snippet:

          LaunchApp(‘JeremyDR’)

          function LaunchApp(Name) {
          alert(Name);
          }

  • mohan chand

    Thanks a lot. Its working.

    • http://codereflex.net Syed Asad Ahmed

      Thats good to know and enjoy programming :-)

  • Vernon Soubble

    I need to run an executable from a web page. I can see how the above may start the exe. But my concern is, the exe is an installed file and it may run ok on the server it was originally installed on, but will it run if someone is running the web site from another system where the exe was never installed?

    Thanks for any help of this.

    • http://codereflex.net Syed Asad Ahmed

      Vernon Soubble:
      What I understand from your question is that you have installed a software on your server and to run that software on your server you need this executable file.If this is the case then the above code will definitely execute your exe file from another system but the exe file will not run properly and will show you some errors like file missing erros because the pre-requisite file for that exe file does not resides on the other system.

      I hope you got my point.

      Cheers!!!!!

      • Vernon Soubble

        Thanks for your reply. I kind of guessed that this would happen. The exe will run, but the DLLs (in this case its a vb exe) are installed on the web page server, not on the remote system that is trying to run the exe.

        I guess I am correct in saying there is no way to exec an exe from a web page unless that exe was installed on the remote system that is trying to exe it.

        Thanks again for you help.

        Vern

        • http://codereflex.net Syed Asad Ahmed

          Hey Vernon Soubble:

          Well you can execute a .exe file for not running a software application from web server but for installing a software that resides on your web server .

          Hope you understand the difference now.

          Cheers !!!

  • http://georgia4ever levan

    thanks a lot! thats great!

  • Chris

    Hi,
    this works great for what I need to do – call an .exe and show the output on the webpage – but is there any way to stop the command window from flashing up every time it’s called?

    Cheers,
    Chris

    • http://codereflex.net Syed Asad Ahmed

      hey Chris:

      can you explain what you are actually trying to achieve,as the command window should not prompt while trying to run the above script.

      • Chris

        It doesn’t prompt, it just flashes up for a second, and then disappears. Is there a way to stop this?

        • http://codereflex.net Syed Asad Ahmed

          let me check this Chris,i’ll get back to you soon.Cheers

          • http://codereflex.net Syed Asad Ahmed

            Hey Chris i have tried this on various platforms and with multiple types of exe files but no command window appeared.
            Can you describe your task in detail.

  • Pingback: 如何使用網頁 執行 .exe 檔 - Firefox、IE - 2012 | Tsung's Blog

  • zepelin

    the Above script doesn’t execute my exe file from the webserver but his looking to run it from my machine.

    • http://codereflex.net Syed Asad Ahmed

      Hey zepelin:

      Can you send me your error message?

  • Gobzero

    the script working thank you very much

    • SyedAsadAhmed

      Thanks Gobzero:

      Keep on visiting CodeReflex.net for more helpful stuff :-)

  • Yogesh Kumar

    I am very new to this stuff, however this is what I wanted to do with an Exe I developed on VB.. I just wanted to know where should I paste this Java Script???

    • SyedAsadAhmed

      Just put this script any where on your webpage.

      Cheers!!!

      • Yogesh Kumar

        That is good, however I don’t own any page? I own the EXE built on VB. does the script above help to open the Exe in web format? if so, where exactly I will paste this script, can you guide me with the steps.. I am not so tech sevy..  Thanks, YK

        • SyedAsadAhmed

          Just create html file and write following code in that file with the path your exe file.

          function LaunchApp() {
          if (!document.all) {
          alert (“This ActiveXObject is only available for Internet Explorer”);
          return;
          }
          var ws = new ActiveXObject(“WScript.Shell”);
          ws.Exec(“D:\yourfile.exe”);
          }

          Click here to Execute your file

  • kashi

    path is on local drive if exe is on server can we run the exe from web browser.

  • Mike

    So is that a script that you can also load exe game file on a html webpage?

    • SyedAsadAhmed

      yes Mike you can load exe game file on a html webpage as well.

      • http://www.facebook.com/rina.nurjanah.5 Rina Nurjanah

        can that script run on latest IE version..???

        • SyedAsadAhmed

          yeah this script can run on latest IE version

    • http://www.facebook.com/rina.nurjanah.5 Rina Nurjanah

      Can this script run on IE early version…???

  • http://www.facebook.com/rina.nurjanah.5 Rina Nurjanah

    Can that script run on IE early Version..??

  • http://www.facebook.com/rina.nurjanah.5 Rina Nurjanah

    I”m soryy, I Revise my question.
    Can that script run on latest version IE…??

  • Mazhar

    How do run .exe present in remote http server using http protocol?

GetSocial