简体   繁体   English

从超链接启动应用程序

[英]Launching application from hyperlink

I wondered if there is a way (on windows) to cause a pre-installed application to launch from a click on a hyperlink. 我想知道是否有办法(在Windows上)通过单击超链接来使预安装的应用程序启动。 For a basic example: 举一个基本的例子:

The user has an application called SuperPing installed on their machine. 用户在其计算机上安装了一个名为SuperPing的应用程序。 If they were to click a link in their browser with the following URL, it would launch the applcation. 如果他们单击浏览器中带有以下URL的链接,它将启动应用程序。

SPing://8.8.4.4

This would cause the following to happen: 这将导致发生以下情况:

"C:\SuperPing.exe" /ip 8.8.4.4

So my question is really, what would be the way to create this hook, to cause things to happen based on a URL. 所以我的问题确实是,创建此挂钩并导致基于URL进行操作的方式是什么? This is very similar to the way in which iPhones can launch specific apps when hooked up correctly to a link. 这与正确连接到链接时iPhone可以启动特定应用程序的方式非常相似。

You can register a custom URL handler when your application is installed. 您可以在安装应用程序时注册自定义URL处理程序。 See MSDN for more information. 有关更多信息,请参见MSDN

Here is the relevant excerpt from the page: 这是该页面的相关摘录:


To register an application to handle a particular URI scheme, add a new key, along with the appropriate subkeys and values, to HKEY_CLASSES_ROOT . 要注册用于处理特定URI方案的应用程序,请向HKEY_CLASSES_ROOT添加一个新键以及相应的子键和值。 The root key must match the URI scheme that is being added. 根密钥必须与要添加的URI方案匹配。 For instance, to add an alert: scheme, add an alert key to HKEY_CLASSES_ROOT , as follows: 例如,要添加一个alert:方案,请向HKEY_CLASSES_ROOT添加一个alert键,如下所示:

HKEY_CLASSES_ROOT
   alert
      URL Protocol = ""

Under this new key, the URL Protocol string value indicates that this key declares a custom pluggable protocol handler. 在此新密钥下, URL Protocol字符串值指示此密钥声明了自定义可插拔协议处理程序。 Without this key, the handler application will not launch. 没有此密钥,处理程序应用程序将无法启动。 The value should be an empty string. 该值应为空字符串。

Keys should also be added for DefaultIcon and shell . 还应该为DefaultIconshell添加密钥。 The Default string value of the DefaultIcon key must be the file name to use as an icon for this new URI scheme. DefaultIcon键的Default字符串值必须是用作此新URI方案的图标的文件名。 The string takes the form path, iconindex with a maximum length of MAX_PATH . 该字符串采用path, iconindex ,最大长度为MAX_PATH The name of the first key under the shell key should be an action verb, such as open . shell键下的第一个键的名称应为动作动词,例如open Under this key, a command key or a DDEEXEC key indicate how the handler should be invoked. 在此键下, command键或DDEEXEC键指示应如何调用处理程序。 The values under the command and DDEEXEC keys describe how to launch the application handling the new protocol. commandDDEEXEC键下的值描述了如何启动处理新协议的应用程序。

Finally, the Default string value should contain the display name of the new URI scheme. 最后, Default字符串值应包含新URI方案的显示名称。 The following example shows how to register an application, alert.exe in this case, to handle the alert scheme. 以下示例显示了如何注册应用程序(在这种情况下) alert.exe来处理警报方案。

HKEY_CLASSES_ROOT
   alert
      (Default) = "URL:Alert Protocol"
      URL Protocol = ""
      DefaultIcon
         (Default) = "alert.exe,1"
      shell
         open
            command
               (Default) = "C:\Program Files\Alert\alert.exe" "%1"

When a user clicks a link containing your custom URI scheme, Windows Internet Explorer launches the pluggable protocol handler registered for that URI scheme. 当用户单击包含您的自定义URI方案的链接时,Windows Internet Explorer会启动为该URI方案注册的可插拔协议处理程序。 If the specified open command specified in the registry contains a %1 parameter, Internet Explorer passes the URI to the registered pluggable protocol handler application. 如果注册表中指定的指定open命令包含%1参数,则Internet Explorer会将URI传递给已注册的可插拔协议处理程序应用程序。


So, in your case you'd add this key: 因此,您需要添加以下密钥:

HKEY_CLASSES_ROOT
   SPing
      (Default) = "URL:SPing Protocol"
      URL Protocol = ""
      DefaultIcon
         (Default) = "SuperPing.exe,1"
      shell
         open
            command
               (Default) = "C:\SuperPing.exe" /url "%1"

Then you would modify your application to take a "/url" command line argument that would be populated with the full URL used to launch your application (so it won't automatically split out the portion after the URL). 然后,您将修改应用程序以使用“ / url”命令行参数,该参数将填充用于启动应用程序的完整URL(因此它不会自动拆分URL后面的部分)。

The syntax is up to you, but it would then be as simple as SPing:8.8.4.4 (no need for the :// ). 语法由您决定,但是它将像SPing:8.8.4.4一样简单(不需要:// )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM