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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3057576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:24:24  来源:igfitidea点击:

How to launch an application from a browser?

windowsinternet-explorerbrowseractivex

提问by Goro

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.

是否可以从浏览器启动应用程序?我不是在谈论从浏览器打开文件(如使用 Adob​​e Reader 打开 PDF),而是打开安装在用户机器上的应用程序的新(空白)实例。

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.

假设情况:用户浏览的网站列出了可以通过 RDP 管理的计算机。他单击指向 192.168.1.10 的链接,该链接会打开 Microsoft RDP 客户端 (mstsc.exe),其中已填写该 IP 地址。

I am talking strictly about Windows universe.

我严格地谈论 Windows 宇宙。

Is that thing even doable outside of ActiveX and IE?

在 ActiveX 和 IE 之外,这件事甚至可行吗?

Is it wise to attempt this in IE with ActiveX?

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

采纳答案by brendan

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.

您无法真正“启动应用程序”。您可以按照您的指示要求用户打开文档(即 PDF),Windows 将尝试使用该文件类型的默认应用程序。许多应用程序有办法做到这一点。

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:

例如,您可以将 RDP 连接保存为 .rdp 文件。在您的网站上放置一个指向类似内容的链接应该允许用户直接启动 RDP 会话:

<a href="MyServer1.rdp">Server 1</a>

回答by pastjean

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

一些应用程序通过协议自行启动。像带有“itms://”链接的 iTunes。但是,我不知道如何在 Windows 中注册它。

回答by Byron Whitlock

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.

我们使用 sonicwall vpn。它启动一个 java 小程序,该小程序启动带有所有凭据设置的 mstc。如果没有 java 小程序或 activex 插件,您真的无法做到这一点。

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.

微软在他们的小型企业服务器上使用这种技术来进入网络。我不会说这是一个糟糕的主意,只要平台独立性不重要。

回答by LiriB

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)

您可以使用 SilverLight 从浏览器启动应用程序(这仅适用于 IE 和 Firefox,较新版本的 chrome 不支持此功能)

Example code here

示例代码在这里

回答by Abhijith C R

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

正确的方法是在 windows 注册表中注册您的自定义 URL 协议,如下所示:

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

添加上述键和值后,从网页中,只需调用 "customurl:\\parameter1=xxx¶meter2=xxx" 。您将收到整个 url 作为 exe 中的参数,您需要在 exe 中对其进行处理。使用您选择的文本更改“customurl”。

回答by zildjohn01

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

我使用本地 Web 服务器和 PHP 实现了同样的目标。我使用了一个包含shell_exec在本地启动应用程序的脚本。

Alternatively, you could do something like this:

或者,您可以执行以下操作:

<a href="file://C:/Windows/notepad.exe">Notepad</a>

回答by JoBaxter

You can use the following:

您可以使用以下内容:

<a href="c:\windows\Notepad.exe" 
type="application/octet-stream">Launch Notepad</a>

From what I remember using file:// is blocked by Chrome and Firefox.

我记得使用 file:// 被 Chrome 和 Firefox 阻止。