AQ Dev
AQ Dev

Reputation: 43

Launch .exe file using Javascript from IE, Chorome and Firefox

I know we can launch .exe file using following code snippet. but this only works for IE. My client very often use Chorome and Firefox as well. How can I modify this snippet to launch the exe from other browsers as well.

var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\User\Desktop\test.exe"; `oShell.ShellExecute(commandtoRun,"","","open","1");`

Also, there any mean to pass any argument to that opening .exe file?

Upvotes: 0

Views: 5943

Answers (2)

Martin
Martin

Reputation: 16300

The best way to achieve this is to have the .exe you want to run register itself with a custom protocol URI Scheme.

For example, lets say you have a program, alert.exe, that will show or send an alert. You could register the URI Scheme alert. Then your link would look like:

<a href="alert:Message to Show">Alert</a>

When the user clicks on the link, the browser will launch your alert.exe and pass the string Message to Show to it.

Upvotes: 1

Maria Saavedra
Maria Saavedra

Reputation: 197

Could an inline script work?

<a href="#" onclick="window.open('file:///C:/User/Desktop/test.exe')">

I'm not sure if you can replicate this on Firefox or Chrome because of security issues.

These links may be helpful:

https://developer.mozilla.org/en-US/Add-ons/Code_snippets/Running_applications

https://developer.chrome.com/extensions/npapi

Upvotes: 0

Related Questions