Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registering a protocol handler in Windows 8

I'm trying to register my application that will handle opening of links, e,g, http://stackoverflow.com. I need to do this explicitly for Windows 8, I have itworking in earlier versions of Windows. According to MSDN this has changed in Win8.

I've been through the Default Programs page on MSDN (msdn.microsoft.com/en-us/library/cc144154.aspx) page on MSDN. It provides a great walkthrough on handling file types but is light on details for protocols. Registering an Application to a URL Protocol only goes over the steps involved in setting up a new protocol, but not how to correctly add a new handler to an existing protocol.

I've also tried the registry settings outlined in other SO posts.

One more thing, the application is not a Metro/Windows Store App, so adding an entry in the manifest won't work for me.

like image 963
Josh Avatar asked Nov 26 '12 06:11

Josh


2 Answers

You were on the right track with the Default Programs web page - in fact, it's my reference for this post.

The following adapts their example:

First, you need a ProgID in HKLM\SOFTWARE\Classes that dictates how to handle any input given to it (yours may already exist):

HKLM\SOFTWARE\Classes
     MyApp.ProtocolHandler //this is the ProgID, subkeys are its properties
        (Default) = My Protocol //name of any type passed to this
        DefaultIcon
           (Default) = %ProgramFiles%\MyApp\MyApp.exe, 0 //for example
        shell
           open
              command
                 (Default) = %ProgramFiles%\MyApp\MyApp.exe %1 //for example

Then fill the registry with DefaultProgram info inside a Capabilities key:

HKLM\SOFTWARE\MyApp
    Capabilities
       ApplicationDescription
           URLAssociations
              myprotocol = MyApp.ProtocolHandler //Associated with your ProgID

Finally, register your application's capabilities with DefaultPrograms:

HKLM\SOFTWARE
      RegisteredApplications
         MyApplication = HKLM\SOFTWARE\MyApp\Capabilities

Now all "myprotocol:" links should trigger %ProgramFiles%\MyApp\MyApp.exe %1.

like image 92
Arithmomaniac Avatar answered Oct 23 '22 22:10

Arithmomaniac


Side note since this is a top answer found when googling this kind of an issue: Make sure the path in the shell command open is a proper path to your application. I spent an entire day debugging issue that seemed only to affect Chrome and Edge on Windows 10. They never triggered the protocol handler while Firefox did. What was the issue? The path to the .bat file used mixed \ and / slashes. Using only proper \ slashes in the path made Edge & Chrome suddenly able to pick up the request.

like image 23
jhaukur Avatar answered Oct 23 '22 23:10

jhaukur