windows 如何创建“自定义协议”并将其映射到应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3964152/
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
How do I create a "custom protocol" and map it to an application?
提问by coderpro.net
How would one go about creating a "custom protocol?" I know you can create a URL protocol by adding a number of registry entries to HKEY_CLASSES_ROOT, but that seems to only work in a browser. I need for it to work in Windows Explorer also.
如何创建“自定义协议”?我知道您可以通过向 HKEY_CLASSES_ROOT 添加多个注册表项来创建 URL 协议,但这似乎只适用于浏览器。我也需要它在 Windows 资源管理器中工作。
I know that I can write a client/server sort of interface, but I think that is overkill for my client's needs (and budget).
我知道我可以编写客户端/服务器类型的接口,但我认为这对于我客户的需求(和预算)来说太过分了。
Long story short...
长话短说...
- A third-party application should call:
tbwx:<row_id>
- My app should load and delete a record from the database.
- 第三方应用程序应该调用:
tbwx:<row_id>
- 我的应用程序应该从数据库中加载和删除一条记录。
It sounds fairly simple (or so I thought). Any ideas?
这听起来相当简单(或者我是这么认为的)。有任何想法吗?
Thanks
谢谢
回答by Jeff Mercado
At least on Windows 7, you can create a custom protocol as long as you add a URL Protocol
value of type REG_SZ
to the key. It doesn't need an actual value, just needs to be present. Here's a simple example of an "Echo Protocol" I just created which works in explorer.
至少在 Windows 7 上,您可以创建自定义协议,只要向键添加URL Protocol
类型值REG_SZ
即可。它不需要实际值,只需要存在即可。这是我刚刚创建的在资源管理器中工作的“回声协议”的一个简单示例。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\echo]
"URL Protocol"=""
@="Echo Protocol"
[HKEY_CLASSES_ROOT\echo\shell]
[HKEY_CLASSES_ROOT\echo\shell\open]
[HKEY_CLASSES_ROOT\echo\shell\open\command]
@="C:\WINDOWS\SYSTEM32\CMD.EXE /Q /C (echo %1) && pause"
I've found it will also work in the keys HKCU\Software\Classes
and HKLM\Software\Classes
too. It isn't listed in the Control Panel\Programs\Default Programs\Set Associations
list however. Other keys might need to be updated or it would have to be registered with Windows somehow.
我发现它也将工作中的键HKCU\Software\Classes
和HKLM\Software\Classes
太。Control Panel\Programs\Default Programs\Set Associations
然而,它并未列在列表中。其他密钥可能需要更新,或者必须以某种方式在 Windows 中注册。
I imagine it is the same or similar in older versions of Windows XP and up.
我想它在旧版本的 Windows XP 及更高版本中是相同或相似的。
回答by Garett
The Registering an Application to a URL Protocolarticle details the process. There is a uilitiyon CodePlexthat can be used to register custom URL protocols. The source code is provided.
将应用程序注册到 URL 协议一文详细介绍了该过程。有一个uilitiy在CodePlex上,可以用来注册自定义URL协议。提供了源代码。