How to run an external program, e.g. notepad, using hyperlink?
Asked Answered
G

5

23

I'm generating an HTML report by C# to print pairs of files in a table which has 3 columns: the first two columns used for the filenames and the 3rd column is a hyperlink Compare - I want this link to run WinMerge to compare to two files and I currently don't know how to do it.

Greerson answered 10/5, 2010 at 2:57 Comment(1)
This is impossible in general, because you cannot know what programs are availab on a particular computer.Housework
G
20

Try this

<html>
    <head>
        <script type="text/javascript">
        function runProgram()
        {
            var shell = new ActiveXObject("WScript.Shell");                 
            var appWinMerge = "\"C:\\Program Files\\WinMerge\\WinMergeU.exe\" /e /s /u /wl /wr /maximize";
            var fileLeft = "\"D:\\Path\\to\\your\\file\"";
            var fileRight= "\"D:\\Path\\to\\your\\file2\"";
            shell.Run(appWinMerge + " " + fileLeft + " " + fileRight);
        }
        </script>
    </head>

    <body>
        <a href="javascript:runProgram()">Run program</a>
    </body>
</html>
Greerson answered 10/5, 2010 at 3:43 Comment(2)
This is what I want. I try and note that we also need to allow the browser to run javascript and ActiveX. Thanks a lot!Greerson
I think this only works on IEJameljamerson
H
16

Sorry this answer sucks, but you can't launch an just any external application via a click, as this would be a serious security issue, this functionality isn't available in HTML or javascript. Think of just launching cmd.exe with args...you want to launch WinMerge with arguments, but you can see the security problems introduced by allowing this for anything.

The only possibly viable exception I can think of would be a protocol handler (since these are explicitly defined handlers), like winmerge://, though the best way to pass 2 file parameters I'm not sure of, if it's an option it's worth looking into, but I'm not sure what you are or are not allowed to do to the client, so this may be a non-starter solution.

Hertahertberg answered 10/5, 2010 at 3:2 Comment(1)
how then is it possible to open github desktop app from a browser page ?Lissy
L
9

The reasonable way how to launch apps from HTML is through url schemes. So you can launch email via mailto: links and irc through irc: links. Individual apps can implement these schemes, but I'm not sure WinMerge does this.

Lulu answered 10/5, 2010 at 3:3 Comment(1)
Microsoft's Quick Assist app has such a scheme: <a href=ms-quick-assist://>Quick Assist</a>. Works like a charm.Another
T
4

Make a batch file and call the bacth file in Window.open. Here how it works

  1. make a file in notepad
  2. write your script : start wmplayer "\dotnet\sc\1234.mp4" /fullscreen
  3. save as : test.bat in \dotnet\sc\test.bat

in html

window.open('file://dotnet/sc/test.bat')

Enjoy..

Termination answered 23/2, 2014 at 10:23 Comment(0)
E
4

I've wrote a small extension to do so.

Since you are creating the page using C# you may want to implement this:

https://github.com/felix-d-git/DesktopAppLink

Basically u are creating some registry entries to parse the links you click in your html page.

The browser will then ask to open the specified app.

C#:

DesktopAppLink.CreateLink("applink.sample", "\"<path to exe>\"", "");

HTML:

<a href="applink.sample:">Run Desktop App</a>

Result:

enter image description here

Eyeleen answered 13/3, 2019 at 10:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.