URI 方案启动 [英] URI scheme launching

查看:24
本文介绍了URI 方案启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我接到了一项任务,要创建一个类似于 callto: 的协议,该协议在单击带有它的链接时会自动启动已安装的应用程序.

I've been given a task to create a protocol similar to callto:, that - upon clicking on a link with it - would automatically launch an installed aplication.

我遵循了微软指南关于如何设计一个方案应该看起来像.

I followed the microsoft guide on how a scheme should look like.

我的方案是这样的:

HKEY_CLASSES_ROOT
   slican
       URL Protocol = ""
       DefaultIcon (Default) = "C:UsersOkabeDesktopslicanSlicanP.exe,1"
       shell
            open
                command (Default) = "C:UsersOkabeDesktopslicanSlicanP.exe" "%1""

我认为这就是全部并使用

I thought that was all and tested it with

 <a href="slican:test">test link</a>
 <a href="slican:0049325778421">test telephone link</a>

没有任何反应.Internet Explorer 询问我是否要搜索可以打开内容的程序,Chrome 没有任何响应,就像我单击了 javascript:void(0) 一样.

There was no reaction whatsoever. Internet Explorer asked me if I want to search for a program that can open the content and Chrome responded with nothing, as if I clicked javascript:void(0).

如何让它发挥作用?

感谢您的帮助!

推荐答案

当我在 Windows 7 上尝试时,您显示的注册对我来说非常好.当我调用时,我代替 SlicanP.exe 注册的本地应用程序运行良好slican: URL 来自 Start |运行 菜单,然后从 Windows 资源管理器的地址栏中.所以注册有效.

The registration you show works perfectly fine for me when I try it on Windows 7. The local app I registered in place of SlicanP.exe ran fine when I invoked a slican: URL from the Start | Run menu, and from within the address bar of Windows Explorer. So the registration works.

请注意 Internet Explorer 在完整性较低的安全上下文中运行,因此它可能无权运行本地程序.当我尝试单击指向 slican: URL 的 HTML 链接,或在地址栏中键入 slican: URL 时,IE 无法执行本地应用程序(即使在提示许可).我必须以管理员身份运行 IE,然后本地应用才能正常运行.

Do be aware that Internet Explorer runs in a lower integrity security context, so it may not have rights to run local programs. When I tried to click on an HTML link to a slican: URL, or type a slican: URL in the address bar, IE had trouble executing the local app (even after prompting for permission). I had to run IE as an administrator, then the local app ran just fine.

此外,您真的不应该直接创建 HKEY_CLASSES_ROOTslican 密钥.创建一个 HKEY_CURRENT_USERSoftwareClassesslican(仅限当前用户)或 HKEY_LOCAL_MACHINESoftwareClassesslican(所有用户).有关详细信息,请参阅 MSDN:

Also, you really should not be creating a HKEY_CLASSES_ROOTslican key directly. Create a HKEY_CURRENT_USERSoftwareClassesslican (current user only) or HKEY_LOCAL_MACHINESoftwareClassesslican (all users) instead. Refer to MSDN for more details:

HKEY_CLASSES_ROOT 密钥

HKEY_CLASSES_ROOT 的合并视图

更新:由于它适用于 Windows 7,因此 Microsoft 可能更改了在 Windows 8 中注册 URL 方案的方式.例如,电话/商店应用程序使用 URI 激活:

Update: Since it works in Windows 7, Microsoft probably changed how URL schemes are registered in Windows 8. For instance, phone/store apps use URI activation:

URI 激活 (XAML).

URI 激活 (HTML)

文档 说有两种方法可以注册自定义 URI 方案:

The documentation says there are two ways to register a custom URI scheme:

Internet Explorer 使用两种机制来注册新的可插入协议处理程序.第一种方法是注册 URI 方案名称及其关联的应用程序,以便使用该方案导航到 URI 的所有尝试都会启动应用程序(例如,注册应用程序以处理 mailto: 或 news: URI).第二种方法使用异步可插拔协议 API,它允许您通过将 URI 方案映射到类来定义新协议.

Internet Explorer uses two mechanisms for registering new pluggable protocol handlers. The first method is to register a URI scheme name and its associated application so that all attempts to navigate to a URI using that scheme launch the application (for example, registering applications to handle mailto: or news: URIs). The second method uses the Asynchronous Pluggable Protocols API, which allows you to define new protocols by mapping the URI scheme to a class.

你正在做第一个.尝试改用第二个.

You are doing the first. Try using the second instead.

但是,我刚刚注意到 MSDN 上的Legacy APIs"部分中列出了Asynchronous Pluggable Protocols",并且有以下注释:

However, I just noticed that "Asynchronous Pluggable Protocols" is listed on MSDN in the "Legacy APIs" section, and it has the following note:

第三方协议实现不会加载到使用 JavaScript 的 Windows 应用商店应用中,或在新的 Windows 用户界面中的 Internet Explorer 中.

Third-party protocol implementations won't load in Windows Store apps using JavaScript, or in the Internet Explorer in the new Windows UI.

所以它在 Windows 8 中可能会也可能不会.

So it may or may not work in Windows 8.

更新:我刚刚发现:

文件类型和 URI 指南

在 Windows 8 中,应用之间的关系及其支持的文件类型与以前版本的 Windows 不同.

In Windows 8, the relationship between apps and the file types they support differs from previous versions of Windows.

演练:使用 Windows 8 自定义协议激活

Windows 8 中的文件类型和协议关联模型已更改.应用不再能够以编程方式将自己设置为文件类型或协议的默认处理程序.相反,现在用户始终控制文件类型或协议的默认处理程序.

The file type and protocol association model has changed in Windows 8. Apps are no longer able to programmatically set themselves as the default handler for a file type or protocol. Instead, now the user always controls what the default handler is for a file type or protocol.

您的应用可以使用现有协议进行通信,例如 mailto,或创建自定义协议.协议激活扩展使您能够定义自定义协议或注册以处理现有协议.

Your app can use existing protocols for communication, such as mailto, or create a custom protocol. The protocol activation extension enables you to define a custom protocol or register to handle an existing protocol.

也看看这个:

在 Windows 8 中以编程方式设置 mailto: 协议处理程序

还有这个:

默认程序

这篇关于URI 方案启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆