Question

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?

Was it helpful?

Solution

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:

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top