15

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.

ashleedawg
  • 20,365
  • 9
  • 72
  • 105
Josh
  • 677
  • 2
  • 9
  • 18

3 Answers3

13

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.

Arithmomaniac
  • 4,604
  • 3
  • 38
  • 58
  • im very new to this concepts. can you please tell me how to run the above code ?? – jammy Jul 27 '14 at 06:58
  • It's not code. You'll need to read up on accessing the Windows registry. The code snippets are keys and values in the registry. – Ian Yates Nov 06 '14 at 05:24
  • If you are not sure if your protocol is defined, you still need to add it like this: `[HKEY_CLASSES_ROOT\myprotocol] (Default)="URL:myprotocol" "URL Protocol"=""` – Daniel Oct 02 '17 at 23:43
  • be sure to put your exe path and %1 inside quotes like `"program files\foo.exe" "%1"` – slf Jan 23 '18 at 17:39
5

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.

jhaukur
  • 111
  • 1
  • 7
-4

LaunchUriAsync(Uri)

Starts the default app associated with the URI scheme name for the specified URI. You can allow the user to specify, in this case.

http://msdn.microsoft.com/library/windows/apps/Hh701476

        // Create the URI to launch from a string.
        var uri = new Uri(uriToLaunch);
        
        // Calulcate the position for the Open With dialog.
        // An alternative to using the point is to set the rect of the UI element that triggered the launch.
        Point openWithPosition = GetOpenWithPosition(LaunchUriOpenWithButton);
        
        // Next, configure the Open With dialog.
        // Here is where you choose the program.
        var options = new Windows.System.LauncherOptions();
        options.DisplayApplicationPicker = true;
        options.UI.InvocationPoint = openWithPosition;
        options.UI.PreferredPlacement = Windows.UI.Popups.Placement.Below;
        
        // Launch the URI.
        bool success = await Windows.System.Launcher.LaunchUriAsync(uri, options);
        if (success)
        {
           // URI launched: uri.AbsoluteUri
        }
        else
        {
            // URI launch failed.  uri.AbsoluteUri

        }
        
not2qubit
  • 14,531
  • 8
  • 95
  • 135
Bruno
  • 498
  • 1
  • 4
  • 9
  • 5
    this details how to launch an via a URI. What I'm trying to do is register my application to be launched when a another app launches a URI like this. – Josh Jan 02 '13 at 02:13