4

I want to associate a custom URL protocol (for example, myprotocol://SomeFolder/SomePage) with a ClickOnce application.

I can create the association without a problem - the issue is that every time the application is updated (which is frequently) the path to the EXE file changes.

Is there any way around this issue?

Tomas Kubes
  • 23,880
  • 18
  • 111
  • 148
Darren
  • 4,408
  • 4
  • 39
  • 57

4 Answers4

4

It seems the answer to this is you can't, however I did come up with a solution.

I created a launcher (very simple application) which finds the shortcut and passes its startup parameters to the ClickOnce application. I need to install the launcher in the traditional way, but the main application can still be updated via ClickOnce when needed.

I found these links useful:

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Darren
  • 4,408
  • 4
  • 39
  • 57
0

Once your application is installed system create a link in the start menu. The link is actually a file with "appref-ms" extension. So, the trick is to register a protocol that will use the "appref-ms" to open the app.

So, when you'r ClickOnce application starts you could create the following registry entry to register your protocol. HKEY_CLASSES_ROOT myprotocol = {Protocol Description} shell open command = explorer %1

That's it. Now when someone will click the url like myprotocol: XXX you'r app will be opened and will be opened "as ClickOnce" application so it will check if there is a new version and so on.

  • I can't get this working (how does it target the .appref-ms file?). This is what I have for my cms: protocol: HKEY_CLASSES_ROOT\cms\shell\open\command\(Default) = explorer %1 I've also tried the path to the appref-ms file too. – Darren Sep 08 '16 at 09:22
0

If you're trying to ClickOnce already adds the appropriate key to HKCR, just without the required URL Protocol value. I added this code to the start of my application logic:

try
{
    RegistryKey rk = Registry.ClassesRoot.OpenSubKey("MyProgramName", true);
    rk.SetValue("URL Protocol", "");
}
catch (Exception ex)
{ 
    // handle, log, etc.
}

Which worked well because that's what I wanted the URL protocol to refer to (e.g "MyProgramName://....". I was able to do this successfully without my application having administrative rights - maybe it'd be required if I was trying to register a different handler though, so YMMV. At the very least, looking at the value in there should give you an idea of how to launch the application properly.

Here's the registry key that got created by default:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\MyAppName]
@="Electronic Data Interchange (EDI) File"
"AppId"="MyAppName.application, Culture=neutral, PublicKeyToken=31fc6d113f9bb401, processorArchitecture=msil"
"DeploymentProviderUrl"="file://server/share/MyAppName/MyAppName.application"
"Guid"="{MY_APP_GUID}"

[HKEY_CLASSES_ROOT\MyAppName\shell]
@="open"

[HKEY_CLASSES_ROOT\MyAppName\shell\open]

[HKEY_CLASSES_ROOT\MyAppName\shell\open\command]
@="rundll32.exe dfshim.dll, ShOpenVerbExtension {MY_APP_GUID} %1"

[HKEY_CLASSES_ROOT\MyAppName\shellex]

[HKEY_CLASSES_ROOT\MyAppName\shellex\IconHandler]
@="{MY_APP_GUID}"

And the code I've posted simply adds a URL Protocol with an empty value under the MyAppName node.

Dan Field
  • 20,885
  • 5
  • 55
  • 71
  • My application name is "CMS" (Assembly Name) but there is no key in HKCR by that name. If I add a file association (.cms) to the ClickOnce options then a .cms key gets created, but that's no help. Maybe you could export your key and post it here (redacted if necessary). Thanks. – Darren Sep 12 '16 at 09:30
  • 1
    Added the reg key. To be honest I'm still not 100% sure why/how it created that key, but I've reproduced it in several environments. – Dan Field Sep 12 '16 at 12:12
  • 1
    Unfortunately i am not able to run a clickonce application (deployed to web) just adding the URL Protocol. URL Protocol launches the application but getting a System.Deployment.Application.InvalidDeploymentException (UriSchemeNotSupported) saying that "Uri scheme is not supported. Only file, HTTP, and HTTPS schemes are supported". I am %100 percent stuck... Even googled the error message but not a single page returned. – Onur Omer Feb 05 '17 at 18:53
  • Darren: since VS2008 SP1, you can add file association in the options of ClickOnce. More details here: https://social.msdn.microsoft.com/Forums/en-US/a38dcdc2-2783-410d-98a2-b32e3226a234/clickonce-loose-file-association-icon-after-updating-manually-with-applicationdeployment – jeanie77 Apr 19 '18 at 09:51
-1

I have made an npm module for this purpose.

Here is the link.

So to do this in nodejs you just need to run the code below:

First Install it

npm i protocol-registry

Then use the code below to register you entry file.

const path = require('path');

const ProtocolRegistry = require('protocol-registry');

console.log('Registering...');
// Registers the Protocol
ProtocolRegistry.register({
    protocol: 'testproto', // sets protocol for your command , testproto://**
    command: `node ${path.join(__dirname, './index.js')} $_URL_`, // $_URL_ will the replaces by the url used to initiate it
    override: true, // Use this with caution as it will destroy all previous Registrations on this protocol
    terminal: true, // Use this to run your command inside a terminal
    script: false
}).then(async () => {
    console.log('Successfully registered');
});

Then suppose someone opens testproto://test then a new terminal will be launched executing :

node yourapp/index.js testproto://test

This module handles all cross platform stuffs.

D_00
  • 1,440
  • 2
  • 13
  • 32
Shubham Kumar
  • 538
  • 5
  • 12