15

我正在尝试注册将处理链接打开的应用程序,例如http://stackoverflow.com。我需要为 Windows 8 明确执行此操作,我在早期版本的 Windows 中使用它。根据MSDN,这在 Win8 中发生了变化。

我浏览了 MSDN 上的默认程序页面 (msdn.microsoft.com/en-us/library/cc144154.aspx) 页面。它提供了有关处理文件类型的出色演练,但对协议的详细信息却很少。 将应用程序注册到 URL 协议仅涉及设置新协议的步骤,而不涉及如何正确地将新处理程序添加到现有协议。

我还尝试了其他 SO 帖子中概述的注册表设置。

还有一件事,该应用程序不是 Metro/Windows Store 应用程序,因此在清单中添加一个条目对我不起作用。

4

3 回答 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.

于 2013-08-28T19:17:41.453 回答
5

旁注,因为这是在谷歌搜索此类问题时找到的最佳答案: 确保 shell 命令 open 中的路径是应用程序的正确路径。我花了一整天的时间调试似乎只影响 Windows 10 上的 Chrome 和 Edge 的问题。它们从未触发协议处理程序,而 Firefox 却触发了。问题是什么?.bat 文件的路径使用了混合的 \ 和 / 斜杠。在路径中仅使用正确的 \ 斜杠使 Edge 和 Chrome 突然能够接收请求。

于 2015-10-14T15:44:25.933 回答
-4

LaunchUriAsync(Uri)

启动与指定 URI 的 URI 方案名称关联的默认应用程序。在这种情况下,您可以允许用户指定。

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

    }
于 2012-12-04T03:22:04.300 回答