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.

0

3 Answers 3

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.

4
  • im very new to this concepts. can you please tell me how to run the above code ??
    – jammy
    Commented Jul 27, 2014 at 6: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
    Commented Nov 6, 2014 at 5: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
    Commented Oct 2, 2017 at 23:43
  • be sure to put your exe path and %1 inside quotes like "program files\foo.exe" "%1"
    – slf
    Commented Jan 23, 2018 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.

3
  • Thanks! In general, things like this should be saved for comments. Commented Apr 5, 2017 at 13:14
  • This should be a comment for the accepted answer as this is not an answer itself.
    – MrTux
    Commented Jan 26, 2018 at 9:55
  • When registering a protocol handler from a .REG script, the path separator \ backslash is the same as the escape character. Path separators need to be in the form [escape-char] [literal-char] which ends up as \\
    – Bilbo
    Commented Feb 7 at 3:42
-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

        }
        
1
  • 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
    Commented Jan 2, 2013 at 2:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.