132

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?

2
  • 2
    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... Commented Jun 28, 2015 at 2:27
  • @georgiaboy82, checking whether the app installed or not is job of frontend developers or backend developers? Commented Dec 23, 2016 at 9:47

8 Answers 8

92

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 open customurl://parameter1=xxx&parameter2=xxx. You will receive the entire url as an argument to the exe, which you'll need to process inside your exe. Replace 'customurl' with the text of your choice.

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

6 Comments

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?
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.
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: <a href = "spustvlc:\\Parameter1=AMT-TC-18493_FM_000000.mp4">VLC</a>
@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?
@AbhijithCR or anyone. Could you provide a full example in the context of a local html file (not in a server) with links to local files to be opened in a custom text editor? <a href="mytexteditorurl://parameter1='C:/localpath/to/myfile.txt'"> is not opening that file in my text editor: instead, I always get an ERR_FILE_NOT_FOUND in my browser. I guess the problem is the way to pass the local file as a parameter but I tried many different back/forward simple/double slash combinations without luck
|
13

@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.

6 Comments

What if I want to add in a 2nd parameter, do I change the last line to: ...\your.exe" ""%%1"" ""%%2"""
@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 same issue here. Did you get this resolved?
@abu, This one worked for me reg add HKCR\%key%\shell\open\command /ve /d ""C:\WINDOWS\system32\notepad.exe" "%%1""
@sintek-solutions Escaping double quotes around executable path like this 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. And you @Gaurav ?
|
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> 

6 Comments

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. codeproject.com/Articles/113678/…
@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.
I think this answer is wrong. You just have to register your own protokol like "mailto". There is no file involved if you call <mailto:[email protected]?In-Reply-To=%3C3469A91.D10AF4C@ example.com%3E> for example (datatracker.ietf.org/doc/html/rfc6068#section-6.1).
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.
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
|
8

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

2 Comments

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...)
you should not do that manually on every user's machine. This is what your application should do during installation process.
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.

Comments

0

I was able to achieve this by an approach which is mentioned here, But You will need to add deep linking to the application, If that's not your app try finding It's deep linking docs.

Comments

-7

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

1 Comment

Silverlight is now dead. 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.
-17

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> 

1 Comment

Note that shell_exec will run applications on the web server. As for the link, it usually causes the file to be downloaded.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.