我试图注册我的应用程序,将处理链接开放,E,克, http://stackoverflow.com 。 我需要为Windows 8明确地做到这一点,我有早期的Windows版本。 根据MSDN,这在Win8中已经发生了变化。
我已经通过MSDN上的MSDN(msdn.microsoft.com/en-us/library/cc144154.aspx)页面上的默认程序页面。 它提供了一个处理文件types的很好的演练,但对协议的细节很less见。 注册一个应用程序到一个URL协议只会涉及到build立一个新的协议所涉及的步骤,而不是如何正确地添加一个新的处理程序到现有的协议。
我也尝试了其他SOpost中列出的registry设置。
还有一件事,该应用程序不是一个Metro / Windowsapp store应用程序,所以在清单中添加一个条目将不适用于我。
你在默认程序网页上的正确轨道 – 事实上,这是我的这篇文章的参考。
以下是他们的例子:
首先,你需要一个HKLM\SOFTWARE\Classes
中的ProgID
来指定如何处理给定的输入(你可能已经存在):
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 info填充注册表:
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
。
注意,因为这是一个顶部的答案,当谷歌搜索这种类型的问题:确保在打开的shell命令的路径是一个适当的路径到您的应用程序。 我花了整整一天的调试问题,似乎只影响在Windows 10上的Chrome和边缘。他们从来没有触发协议处理程序,而Firefox的。 这是什么问题? .bat文件的路径使用混合\和/斜杠。 在路径中只使用正确的\斜杠,Edge&Chrome突然可以提取请求。
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 }