windows URI 方案启动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24455311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
URI scheme launching
提问by Sates
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.
我接到了一个任务来创建一个类似于 callto: 的协议,当点击它的链接时,它会自动启动一个已安装的应用程序。
I followed the microsoft guideon how a scheme should look like.
我遵循了关于计划应该如何的微软指南。
My scheme looks like this:
我的方案是这样的:
HKEY_CLASSES_ROOT
slican
URL Protocol = ""
DefaultIcon (Default) = "C:\Users\Okabe\Desktop\slican\SlicanP.exe,1"
shell
open
command (Default) = "C:\Users\Okabe\Desktop\slican\SlicanP.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>
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).
没有任何反应。Internet Explorer 询问我是否要搜索可以打开内容的程序,Chrome 没有任何响应,就像我单击了 javascript:void(0) 一样。
How to get that worked?
如何让它发挥作用?
Thank you for your help!
感谢您的帮助!
回答by Remy Lebeau
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.
当我在 Windows 7 上尝试时,您显示的注册对我来说非常好。当我slican:
从Start | Run
菜单和 Windows 资源管理器的地址栏中调用URL时,我代替 SlicanP.exe 注册的本地应用程序运行良好。所以注册工作。
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.
请注意 Internet Explorer 在完整性较低的安全上下文中运行,因此它可能无权运行本地程序。当我尝试单击指向slican:
URL的 HTML 链接或slican:
在地址栏中键入URL 时,IE 无法执行本地应用程序(即使在提示许可之后)。我不得不以管理员身份运行 IE,然后本地应用程序运行得很好。
Also, you really should not be creating a HKEY_CLASSES_ROOT\slican
key directly. Create a HKEY_CURRENT_USER\Software\Classes\slican
(current user only) or HKEY_LOCAL_MACHINE\Software\Classes\slican
(all users) instead. Refer to MSDN for more details:
此外,您真的不应该HKEY_CLASSES_ROOT\slican
直接创建密钥。改为创建HKEY_CURRENT_USER\Software\Classes\slican
(仅限当前用户)或HKEY_LOCAL_MACHINE\Software\Classes\slican
(所有用户)。有关详细信息,请参阅 MSDN:
Merged View of HKEY_CLASSES_ROOT
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:
更新:由于它适用于 Windows 7,Microsoft 可能更改了在 Windows 8 中注册 URL 方案的方式。例如,电话/商店应用程序使用 URI 激活:
The documentationsays there are two ways to register a custom URI scheme:
文档说有两种方法可以注册自定义 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.
Internet Explorer 使用两种机制来注册新的可插入协议处理程序。第一种方法是注册 URI 方案名称及其关联的应用程序,以便使用该方案导航到 URI 的所有尝试都会启动应用程序(例如,注册应用程序以处理 mailto: 或 news: URI)。第二种方法使用异步可插拔协议 API,它允许您通过将 URI 方案映射到类来定义新协议。
You are doing the first. Try using the second instead.
你在做第一个。尝试改用第二个。
However, I just noticed that "Asynchronous Pluggable Protocols" is listed on MSDN in the "Legacy APIs" section, and it has the following note:
但是,我刚刚注意到 MSDN 上的“Legacy APIs”部分中列出了“Asynchronous Pluggable Protocols”,它有以下注释:
Third-party protocol implementations won't load in Windows Store apps using JavaScript, or in the Internet Explorer in the new Windows UI.
第三方协议实现不会加载到使用 JavaScript 的 Windows 应用商店应用程序中,也不会加载到新 Windows UI 中的 Internet Explorer 中。
So it may or may not work in Windows 8.
所以它可能会或可能不会在 Windows 8 中工作。
Update: I just found this:
更新:我刚刚发现这个:
Guidelines for file types and URIs
In Windows?8, the relationship between apps and the file types they support differs from previous versions of Windows.
在 Windows?8 中,应用程序和它们支持的文件类型之间的关系与以前版本的 Windows 不同。
Walkthrough: using Windows 8 Custom Protocol Activation
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.
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,或创建自定义协议。协议激活扩展使您能够定义自定义协议或注册以处理现有协议。
Also have a look at this:
也看看这个:
Setting mailto: protocol handler programmatically in Windows 8
在 Windows 8 中以编程方式设置 mailto:协议处理程序
And this:
和这个:
回答by Andrei
if you go to C:\Users\\AppData\Local\Google\Chrome\User Data
如果你去 C:\Users\\AppData\Local\Google\Chrome\User Data
You can edit the Local State file
您可以编辑本地状态文件
Search for protocol_handler
搜索 protocol_handler
The syntax here is a key value pair. I usually copy two mailto: and make sure that you set your protocols to false. This will mean that chrome will treat your new protocols as URI_Handler events
这里的语法是键值对。我通常会复制两个 mailto: 并确保将协议设置为 false。这意味着 chrome 会将您的新协议视为 URI_Handler 事件
回答by kolobok
If you have troubles with configuring custom URI scheme, you can compare your own configuration with existing one. For example, "HKEY_CLASSES_ROOT/mailto" - most likely you have it already in your system.
如果您在配置自定义 URI 方案时遇到问题,可以将您自己的配置与现有配置进行比较。例如,“HKEY_CLASSES_ROOT/mailto”——很可能你的系统中已经有了它。