在Windows 8中注册协议处理程序

时间:2012-11-26 06:46:21

标签: windows windows-8

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

我已经浏览了MSDN上MSDN(msdn.microsoft.com/en-us/library/cc144154.aspx)页面上的“默认程序”页面。它为处理文件类型提供了很好的演练,但是对协议的细节很有帮助。 MSDN仅涉及设置新协议所涉及的步骤,而不是如何正确地将新处理程序添加到现有协议。

我也尝试了其他SO帖子中列出的注册表设置。

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

3 个答案:

答案 0 :(得分:12)

您使用默认程序网页走在正确的轨道上 - 事实上,这是我对此帖子的参考。

以下内容适应他们的例子:

首先,你需要ProgID HKLM\SOFTWARE\Classes来指示如何处理给你的任何输入(你的可能已存在):

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

然后在Capabilities密钥内填写DefaultProgram信息注册表:

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

最后,使用DefaultPrograms注册应用程序的功能:

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

现在所有“myprotocol:”链接都应该触发%ProgramFiles%\MyApp\MyApp.exe %1

答案 1 :(得分:4)

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

答案 2 :(得分:-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

    }