如何从浏览器启动应用程序?

是否可以从浏览器启动应用程序?我并不是说要从浏览器打开一个文件(比如用 Adobe Reader 打开一个 PDF) ,而是要打开一个安装在用户机器上的新的(空白的)应用程序实例。

假设的情况: 用户浏览一个网站,列出了可以通过 RDP 管理的计算机。他点击一个到192.168.1.10的链接,该链接打开 Microsoft RDP 客户端(mstsc.exe) ,IP 地址已经填写完毕。

我说的是严格意义上的 Windows 宇宙。

在 ActiveX 和 IE 之外,这样的事情还能做吗?

在 IE 中尝试使用 ActiveX 是否明智?

238265 次浏览

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.

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

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>

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>

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

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.

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