Registering a protocol handler in Windows 8

后端 未结 3 1923
无人及你
无人及你 2020-12-05 15:31

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 ear

相关标签:
3条回答
  • 2020-12-05 15:39

    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.

    0 讨论(0)
  • 2020-12-05 15:43

    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.

    0 讨论(0)
  • 2020-12-05 15:47

    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
    
        }
    
    0 讨论(0)
提交回复
热议问题