Sometimes you need a solution to open an application on client machine when user clicks on a link. It’s a common scenario in some cases.
For example, you probably have seen
mailto: url scheme. When you click on such links, the default mail application will open to send an email. Or as another example you can see such feature in SharePoint applications which opens
OneDrive for Business for synchronizing documents or use other office applications. Also
skype: is another example.
Also you probably have seen Report Builder application in SSRS. When you click on report builder link in SSRS, at the first time, the report builder application will be installed on your client and the next time which you click on that link, the application opens on your client.
To have such feature in your application you can use either of the following options:
- You can register an application to a custom URI Scheme, then you can activate that application by the specified URL and pass parameters in URL. For more information take a look at: Registering an Application to a URI Scheme.
You can use a
ClickOncedeployment by specifying an installation URL. Then you can simply open the application using that URL and pass parameters to the application using query string.
For more information take a look at: How to: Specify the Location Where End Users Will Install From – How to: Retrieve Query String Information in an Online ClickOnce Application
Be careful! You may introduce security holes to your application and clients. When passing data you should be careful about security vulnerabilities like Injection, Insecure Direct Object References, SensitiveData Exposure, and so on.
Usually you should only expose a minimal secure set of features of the program using url and pend the operations to users confirmation. For example
mailto: activates the mail program with some minimal data but doesn’t send email. The users should press send themselves.
I’ve created an example that demonstrate the feature. It handles
myapp: url scheme and shows a message box containing the values that is passed though url to the application.
The sample contains 2 projects:
- A Windows Forms Application that will be installed and will run when a link of “myapp:” protocole is clicked.
- A Visual Studio Setup Project which installs the application and also setup registery settings to let the windows application handle “myapp:” protocole.
You can download the code here: