How to register a protocol handler in Windows 8?

I have a small project for handling tel: protocol links . This is a desktop application that I am developing using Visual Studio 2013 Community Edition.

Previously, I used to register a handler with a simple registry modification:

 Microsoft.Win32.Registry.SetValue(registryKey, string.Empty, registryValue, Microsoft.Win32.RegistryValueKind.String); Microsoft.Win32.Registry.SetValue(registryKey, "URL Protocol", String.Empty, Microsoft.Win32.RegistryValueKind.String); registryKey = @"HKEY_CLASSES_ROOT\tel\shell\open\command"; registryValue = "\"" + AppDomain.CurrentDomain.BaseDirectory + "TelProtocolHandler.exe\" \"%1\""; Microsoft.Win32.Registry.SetValue(registryKey, string.Empty, registryValue, Microsoft.Win32.RegistryValueKind.String); 

However, this no longer works on Windows 8. Although the registry key has the desired value, the links are still being processed by another application. My tool does not even appear in the selection of the protocol handler:

enter image description here

I looked through the Walkthrough: Using Windows 8 User Protocol Activation , but I cannot associate the specified information with my application. The article mentions the .appxmanifest file, which I do not have in my project, and I cannot add it as a new element.

+5
source share
1 answer

Asking a question, I came across Registering a protocol handler in Windows 8

The surest answer I gave was on the right track, although there were other problems. In the end, this is what I ended up with:

 // Register as the default handler for the tel: protocol. const string protocolValue = "TEL:Telephone Invocation"; Registry.SetValue( @"HKEY_CLASSES_ROOT\tel", string.Empty, protocolValue, RegistryValueKind.String ); Registry.SetValue( @"HKEY_CLASSES_ROOT\tel", "URL Protocol", String.Empty, RegistryValueKind.String ); const string binaryName = "tel.exe"; string command = string.Format( "\"{0}{1}\" \"%1\"", AppDomain.CurrentDomain.BaseDirectory, binaryName ); Registry.SetValue( @"HKEY_CLASSES_ROOT\tel\shell\open\command", string.Empty, command, RegistryValueKind.String ); // For Windows 8+, register as a choosable protocol handler. // Version detection from https://stackoverflow.com/a/17796139/259953 Version win8Version = new Version( 6, 2, 9200, 0 ); if( Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version >= win8Version ) { Registry.SetValue( @"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TelProtocolHandler", string.Empty, protocolValue, RegistryValueKind.String ); Registry.SetValue( @"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TelProtocolHandler\shell\open\command", string.Empty, command, RegistryValueKind.String ); Registry.SetValue( @"HKEY_LOCAL_MACHINE\SOFTWARE\TelProtocolHandler\Capabilities\URLAssociations", "tel", "TelProtocolHandler", RegistryValueKind.String ); Registry.SetValue( @"HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications", "TelProtocolHandler", @"SOFTWARE\TelProtocolHandler\Capabilities", RegistryValueKind.String ); } 

TelProtocolHandler is the name of my application and should be replaced with any name of your handler.

The accepted answer in another question also has ApplicationDescription in the registry. I did not see the same key for any of the registered registered handlers that I checked, so I left it and could not detect any problems.

Another key problem was that all this would not work if my application installing the handler would be 32 bits. When the entries were made in Wow6432Node, I could not select the handler as the default value for this protocol. It took me a while to figure this out because my application was compiled as AnyCPU. This is the first time I have missed this little flag in the project properties:

enter image description here

+8
source

Source: https://habr.com/ru/post/1208138/


All Articles