119

Is it possible to launch an application from a browser? I am not talking about opening a file from a browser (like open a PDF with Adobe Reader), but rather opening a new (blank) instance of an application that is installed on the user's machine.

Hypothetical situation: User browses a website that lists computers that can be managed via RDP. He clicks on a link to 192.168.1.10, that link opens Microsoft RDP client (mstsc.exe) with that ip address already filled out.

I am talking strictly about Windows universe.

Is that thing even doable outside of ActiveX and IE?

Is it wise to attempt this in IE with ActiveX?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Goro
  • 9,919
  • 22
  • 74
  • 108
  • 2
    http://roblox.com is a gaming site that every user has to install their client and visit their website to launch the game client. So they have it set up where they launch an application directly from their site. I have looked through thier source and they don't do it the way brendan says... – georgiaboy82 Jun 28 '15 at 02:27
  • @georgiaboy82, checking whether the app installed or not is job of frontend developers or backend developers? – Sai M. Dec 23 '16 at 09:47

7 Answers7

79

The correct method is to register your custom URL Protocol in windows registry as follows:

[HKEY_CLASSES_ROOT\customurl]
@="Description here"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\customurl\shell]

[HKEY_CLASSES_ROOT\customurl\shell\open]

[HKEY_CLASSES_ROOT\customurl\shell\open\command]
@="\"C:\\Path To Your EXE\\ExeName.exe\" \"%1\""

Once the above keys and values are added, from the web page, just call "customurl:\\parameter1=xxx&parameter2=xxx" . You will receive the entire url as the argument in exe, which you need to process inside your exe. Change 'customurl' with the text of your choice.

Abhijith C R
  • 1,440
  • 1
  • 12
  • 12
  • 3
    Hello.... how can I detect if an application is not installed and if it is not, the installer should be downloaded? for example, if I call `customurl://` in the browser using JavaScript, and if the application is installed, it is run, however, if the application is not installed, and that URL is called in Chrome, the Google search page appears with the result of `customurl://`. Do you know how to do it? – jstuardo Oct 22 '20 at 21:30
  • 1
    Not sure if there is another clean way to go about it, but a quick idea that came to me is - If you can make your app report to the server that it is open, and if that times out, redirect the user to a download page or a web implementation of your application. Make use of a token passed on from the web page to identify the client instance while the application is reporting. – Abhijith C R Dec 25 '20 at 20:07
  • Hello ... I need open VLC with this. but if I add paremeter (video file in the same folder as HTML file) vlc answers me: Can not open MRL 'file:///C:/Windows/system32/spustvlc%3A%255C%255CParameter1%3DAMT-TC-18493_FM_000000.mp4'. my command is: "c:\Program Files (x86)\VideoLAN\VLC\vlc.exe" "%1" and in html: VLC – fik236 Apr 13 '21 at 07:46
  • @AbhijithCR can You please provide some help regarding processing the received parameters exe-side? I'm trying to catch argument parameters as `Main(string[] args)` then pass it to my Form with `Application.Run(new Form1(args));` but in _Form1.cs_ code `args.Length > 0` condition returns false value - what am I doing wrong? – Viktor Oct 27 '21 at 10:00
  • How can I execute a .bat file from Chrome? Basically, I want a fast way to use msra.exe an type down the hostname on a text box, hit Enter and connect to remote computer – Verminous Oct 18 '22 at 21:51
12

You can't really "launch an application" in the true sense. You can as you indicated ask the user to open a document (ie a PDF) and windows will attempt to use the default app for that file type. Many applications have a way to do this.

For example you can save RDP connections as a .rdp file. Putting a link on your site to something like this should allow the user to launch right into an RDP session:

<a href="MyServer1.rdp">Server 1</a>
brendan
  • 29,308
  • 20
  • 68
  • 109
  • 1
    I'm just learning what ActiveX is and I red that it can be used to run applications inside a browser. So shouldn't this be possible? I tried following these directions to launch Notepad from the browser, though it didn't work. http://www.codeproject.com/Articles/113678/How-to-execute-a-Local-File-using-HTML-Application – Celeritas Apr 13 '16 at 23:05
  • 3
    @Celeritas: this only works in Windows and older versions of IE. This is an old technology that is getting phased out, and none too soon. – siride Aug 20 '18 at 20:10
  • 2
    I think this answer is wrong. You just have to register your own protokol like "mailto". There is no file involved if you call for example (https://datatracker.ietf.org/doc/html/rfc6068#section-6.1). – The incredible Jan Sep 07 '21 at 13:07
  • 3
    It is unfortunate that this is the accepted answer as it is wrong. The answer by @abhijith is correct. We do it with our Windows exe. Our users can email a URL like "myapp://do-this" and as long as the protocol has been registered the program opens. – Tony Sep 21 '21 at 21:51
  • How can I execute a .bat file from Chrome? Basically, I want a fast way to use msra.exe an type down the hostname on a text box, hit Enter and connect to remote computer – Verminous Oct 18 '22 at 21:51
11

@AbhijithCR 's reply works well. To register the protocol via a .bat file, do something like this

set key=customurl 
reg add HKCR\%key% /ve /d "URL:Description" 
reg add HKCR\%key% /v "URL Protocol" /d "" 
reg add HKCR\%key%\shell 
reg add HKCR\%key%\shell\open 
reg add HKCR\%key%\shell\open\command /ve /d ""c:\path to\your.exe" ""%%1"""

For me getting all the quotes and the double percent signs right was the tricky part.

carl
  • 383
  • 1
  • 5
  • 10
  • What if I want to add in a 2nd parameter, do I change the last line to: ...\your.exe" ""%%1"" ""%%2""" – Off The Gold Nov 30 '21 at 20:16
  • @carl I tried this but it fails in the last line (error message: "_incorrect syntax_"). In my case, `reg add HKCR\npadpp\shell\open\command /ve /d ""C:\Program Files (x86)\Notepad++\notepad++.exe" ""%%1"""` ... any clues? (Windows 7) – abu Feb 22 '22 at 20:26
  • @abu same issue here. Did you get this resolved? – SinTek Solutions Mar 11 '22 at 20:03
  • @abu, This one worked for me reg add HKCR\%key%\shell\open\command /ve /d ""C:\WINDOWS\system32\notepad.exe" "%%1"" – Gaurav Jun 13 '22 at 12:19
  • 1
    @sintek-solutions Escaping double quotes around executable path [like this](https://community.notepad-plus-plus.org/topic/18130/replace-notepad/4?_=1655148848879&lang=en-US) registered the protocol without errors: `reg add HKCR\%key%\shell\open\command /ve /d "\"C:\Program Files (x86)\Notepad++\notepad++.exe\" \"%%1\""`. But I still [couldn't make my links work](https://stackoverflow.com/questions/3057576/how-to-launch-an-application-from-a-browser/67688650?noredirect=1#comment128259749_61136606). And you @Gaurav ? – abu Jun 13 '22 at 23:09
  • How can I execute a .bat file from Chrome? Basically, I want a fast way to use msra.exe an type down the hostname on a text box, hit Enter and connect to remote computer. – Verminous Oct 18 '22 at 21:13
8

Some applications launches themselves by protocols. like itunes with "itms://" links. I don't know however how you can register that with windows.

pastjean
  • 1,307
  • 11
  • 21
  • I know this thread is old, I have the same problem. There is tons of information on how to install protocol handler(s), but I can't do that at work on every user's machine (the IT would literally kill me...) – nurchi Sep 19 '14 at 17:01
  • 8
    you should not do that manually on every user's machine. This is what your application should do during installation process. – Mikhail Jan 13 '16 at 14:03
3

We use a sonicwall vpn. It launches a java applet that launches mstc with all the credentials setup. You really can't do this without a java applet or activex plugin.

Microsoft uses this technique itself on their small business server for getting inside the network. I wouldn't say it is a terrible idea, as long as platform independence isn't important.

Byron Whitlock
  • 52,691
  • 28
  • 123
  • 168
-6

You can use SilverLight to launch an application from the browser (this will work only on IE and Firefox, newer versions of chrome don't support this)

Example code here

Community
  • 1
  • 1
LiriB
  • 814
  • 8
  • 12
  • 1
    [Silverlight is now dead](https://support.microsoft.com/en-gb/help/4511036/silverlight-end-of-support#:~:text=Microsoft%20Silverlight%20will%20reach%20the,support%20on%20October%2012%2C%202021.). Microsoft (or anyone else for that matter) no longer support it. TBH this was actually one of the reasons for it's demise, it being able to do stuff like this is a massive security hole. – Liam Jun 26 '20 at 14:01
-16

I achieved the same thing using a local web server and PHP. I used a script containing shell_exec to launch an application locally.

Alternatively, you could do something like this:

<a href="file://C:/Windows/notepad.exe">Notepad</a>
zildjohn01
  • 11,339
  • 6
  • 52
  • 58
  • 36
    Note that `shell_exec` will run applications on the web server. As for the link, it usually causes the file to be downloaded. – James P. Aug 13 '13 at 16:54