3

I want to launch a local exe-file (without saving it to another location first) upon clicking on a link on a local html file.

It either needs to work in IE, Firefox, Chrome or Opera, I don't care. It's just for a presentation tomorrow.

6
  • 2
    Think about the security implications. We don't want people firing up local applications when we click on links. You can, however, associate specific mime types to specific applications. That's how iTunes fires up when you request iTunes-related content. Commented Mar 31, 2011 at 21:08
  • Yeah I know, but its just for a presentation tomorrow. The other option is having the application running and pressing alt-tab to switch to it. Commented Mar 31, 2011 at 21:12
  • Do that. It's no shame to have the app already running, and switching to it to illustrate something Commented Mar 31, 2011 at 21:16
  • Yeah, you're right. I put it on the first spot of my Windows 7-superbar. Now I can launch it pressing Windows + 1 secretely (without jumping through Windows in the Alt+Tab-menu. Commented Mar 31, 2011 at 21:20
  • @Hedge - how's this for an ugly hack that doesn't deserve an answer? - change your firefox application options (Tools->Options->Applications) so a common file type is handled by your local app. Maybe change XML from 'Always Ask' or whatever's there currently to your app. Then, make your link point to an XML file. Not sure if it would work but it wouldn't hurt to try. Commented Mar 31, 2011 at 21:21

5 Answers 5

1

It's simply not possible. If it was, it would be considered a security flaw and fixed. On Firefox within hours, on IE within some months.

UPDATE: You could try registering your custom protocol: http://openwinforms.com/run_exe_from_javascript.html

But I believe the browser will still prompt you whether you want to run the app.

Sign up to request clarification or add additional context in comments.

5 Comments

I'd have no problem lowering any security restrictions for that one particular case.
HTML security is dependent on the source site. It would not be considered a security flaw to launch an application from a trusted HTML file loaded from the local computer or corporate internet. And in fact this is generally the rule used when loading ActiveX plugins, which are similar in capability to an application launch.
@Ben Voigt: I consider the ActiveX to be security flaw itself.
Doesn't Java also use the classpath when determining applet permissions?
It is possible to run an .exe in an emulator in the browser, if the guest operating system supports it.
1

I want to share my experience.

The accepted response says that it is not possible but it is quite possible indirectly.

If you want to execute an exe on a pc, it means that you have acces on this pc and you can install your exe on that machine.

In my case, I had to take a 3D scan from a 3D scanner via a web application. It seemed impossible at the beginning.

After lots of research, I found that we can send socket messages via javascript.

It means that if we had an application which listens a specific port, it can communicate with a website.

Let's explain how I did this.

In my web application, I created a javascript method like this :

    function openCapron3DScanner(foot) {
      $("#div-wait").show();

      //Creates a web socket pointed to local and the port 21000
      var ws = new WebSocket("ws://127.0.0.1:21000");
      ws.onopen = function () {

      //Sends the socket message to the application which listens the port 21000  
      ws.send(foot + "-" + @ProjectHelper.CurrentProject.Proj_ID);

     };
      ws.onerror = function myfunction() {
          $("#div-wait").hide();
          alert("Erreur connection scanner.");
      }

      ws.onmessage = function (evt) {
        //Receives the message and do something...
        var received_msg = evt.data;
         if (received_msg == "ErrorScan") {
            alert("Erreur scan.");
         }
         else {
            refreshCurrentProject();
         }
     };
    ws.onclose = function () {
        $("#div-wait").hide();
    };
};

And I created a windows forms application who listens the localhost and port 21000. This application is hidden, only shown in icon tray. The only thing to do is to add the application on windows startup via code on the first load to assure that the next restart of windows it will be executed and listen the port.

      private static WebSocketServer wsServer;
      static WebSocketSession LastSession;

      private void Form1_Load(object sender, EventArgs e)
      {
        wsServer = new WebSocketServer();
        int port = 21000;
        wsServer.Setup(port);

        wsServer.NewMessageReceived += WsServer_NewMessageReceived;

        wsServer.Start();
      }



    private static void WsServer_NewMessageReceived(WebSocketSession session, string value)
    {
        if (value.StartsWith("ScanComplete-"))
        {
            //If the scan is ok, uploads the result to the server via a webservice and updates the database.
            UploadImage(value);

            //Sends a confirmation answer to the web page to make it refresh itself and show the result.
            if (LastMacSession != null)
                LastMacSession.Send("ScanComplete");
        }
        else if (value == "ErrorScan")
        {
            //If the C++ application sends an error message
            if (LastMacSession != null)
                LastMacSession.Send("ErrorScan");
        }

        else//call the 3D Scanner from the web page
        {
            LastSession = session;//Keeps in memory the last session to be able to answer via a socket message

            //Calls the C++ exe with parameters to save the scan in the related folder.
            //In could be don in this same application if I had a solution to consume the scanner in C#.
            var proc = System.Diagnostics.Process.Start(@"C:\Program Files\MyProjectFolder\MyScannerAppC++.exe", projectID + " " + param);
        }
    }

I hope it will help.

Comments

0

Use System.Diagnostics.Process.Start() method.

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Process.Start("notepad.exe");
    }

You'll have to use C#, but since that's on your post, it should work. You'll also need the full path, if the file is not in your environment path that's loaded in memory.

For a 'regular link' you'd still need to place this in an ASPX page.....

<a href="test" onclick="<% System.Diagnostics.Process.Start("notepad.exe"); %>">Click me</a>

We're getting really fugly now though.

13 Comments

Yep just tested it works fine. protected void LinkButton1_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("notepad.exe"); }
@John Batdorf - That's the server. It's likely the OP's local machine and server aren't the same machine.
Corbin, not sure what you mean? Umm I read it to mean he wanted to open an exe locally....
Sorry, for not being clear. I want to run an exe (which is coded in C#) from a browser via clicking a link.
You want to run the exe on the server, or the client machine?
|
0

You can't run an exe file on a website. (First, if it's a Linux server, exe files won't run on it and second, if you're on a Windows server, your host would kill the program immediately. And probably terminate your account.)

That link (assuming it was Play Now!) will just allow your user to download the file. (C:\Program Files\World of Warcraft\ exists on your computer, but it doesn't exist on the web server.)

Comments

0

You could setup a custom protocol on your local OS, if it's Windows, in regedit. Check out this and this.

Then you create a simple HTML page, and place a link, something like this :

<a href="presentation://C:\\start.exe/">Start!</a>

Given that you registered your custom "presentation" protocol, and configured it correctly in the registry, the application should launch when you click that link.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.