Launching application from hyperlink
.net, c#
Solution
You can register a custom URL handler when your application is installed. See MSDN for more information.
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`. The root key must match the URI scheme that is being added. For instance, to add an `alert:` scheme, add an `alert` key to `HKEY_CLASSES_ROOT`, as follows:
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. 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`. The `Default` string value of the `DefaultIcon` key must be the file name to use as an icon for this new URI scheme. The string takes the form `path, iconindex` with a maximum length of `MAX_PATH`. The name of the first key under the `shell` key should be an action verb, such as `open`. Under this key, a `command` key or a `DDEEXEC` key indicate how the handler should be invoked. The values under the `command` and `DDEEXEC` keys describe how to launch the application handling the new protocol.
Finally, the `Default` string value should contain the display name of the new URI scheme. The following example shows how to register an application, `alert.exe` in this case, to handle the alert scheme.
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. 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.
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).
The syntax is up to you, but it would then be as simple as `SPing:8.8.4.4` (no need for the `://`).
Problem
I wondered if there is a way (on windows) to cause a pre-installed application to launch from a click on a hyperlink. For a basic example: The user has an application called SuperPing installed on their machine. If they were to click a link in their browser with the following URL, it would launch the applcation. ``` 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. This is very similar to the way in which iPhones can launch specific apps when hooked up correctly to a link.