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.