Recently we had a requirement to launch a .NET desktop application installed in the user’s machine from within Dynamics 365 and also pass parameters to it.
One of the ways of implementing is by using the Custom URL Protocol.
Modern browsers and operating systems allow us to implement a custom URL protocol and register an external application to handle it. So when a user clicks on the link that uses that custom URL Protocol, the browser will open the application that is registered.
Check a few examples here
So, let us start and register our Custom URL Protocol.
Below is the source code for creating a new key
var applicationPath = @"C:\MyParamApp\MyApp\bin\Debug\MyApp.exe"; var KeyTest = Registry.CurrentUser.OpenSubKey("Software", true).OpenSubKey("Classes", true); RegistryKey key = KeyTest.CreateSubKey("OpenAppP"); key.SetValue("URL Protocol", "OpenAppP"); key.CreateSubKey(@"shell\open\command").SetValue("", "\"" + applicationPath + "\" \"%1\"");
Here OpenAppP is the protocol name and the application path that holds the path of application that we want to execute.
For key.CreateSubKey we have specified %1 for passing the parameter.
If we do not want to pass the parameter then we do not need to append it.
On running the above code, we can see the key added with the value specified
Below is the source code of our console application, basically it reads and writes the parameter in the output window.
Below is our Html page that we will call from within a button on a form from Dynamics 365 and which will open the MyApp.exe in turn.
Here we have published the page in Azure.
The html page on onload will retrieve the id query parameter and append it to the link for the custom protocol
Back in CRM, we have a custom ribbon button named Open Console App added with the following definition.
Url Command Action and Crm Parameter in it to pass the id.
Clicking on the button
as expected, opens the alert along with opening the console app with the parameter passed to it.
Get more details
Hope it helps..
2 thoughts on “Use custom browser protocol to launch desktop applications from Dynamics 365”