如何在 Windows 中注册自定义 URL 协议? [英] How do I register a custom URL protocol in Windows?
本文介绍了如何在 Windows 中注册自定义 URL 协议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 Windows 中注册自定义协议,以便在单击电子邮件或网页中的链接时打开我的应用程序并将 URL 中的参数传递给它?
How do I register a custom protocol with Windows so that when clicking a link in an email or on a web page my application is opened and the parameters from the URL are passed to it?
推荐答案
转到
Start
然后在Find
中输入regedit
->它应该打开Registry editor
Go to
Start
then inFind
typeregedit
-> it should openRegistry editor
在HKEY_CLASSES_ROOT
上点击鼠标右键,然后New
-> Key
Click Right Mouse on HKEY_CLASSES_ROOT
then New
-> Key
- 在 Key 中给出你想要调用 url 的小写名称(在我的例子中是
testus://sdfsdfsdf
)然后点击 Right Mousetestus
-> 然后New
->String Value
并添加不带值的URL protocol
.
- In the Key give the lowercase name by which you want urls to be called (in my case it will be
testus://sdfsdfsdf
) then Click Right Mouse ontestus
-> thenNew
->String Value
and addURL protocol
without value.
- 然后像使用协议一样添加更多条目( Right Mouse
New
->Key
)并创建像testus<这样的层次结构/code> ->
看起来像:shell
->open
->command
并在command
内部更改(默认)
到您要启动的.exe
所在的路径,如果您想将参数传递给您的 exe,则将 exe 的路径包裹在""
中并添加 <代码>"%1""c:\testing\test.exe" "%1"
- Then add more entries like you did with protocol ( Right Mouse
New
->Key
) and create hierarchy liketestus
->shell
->open
->command
and insidecommand
change(Default)
to the path where.exe
you want to launch is, if you want to pass parameters to your exe then wrap path to exe in""
and add"%1"
to look like:"c:\testing\test.exe" "%1"
- 要测试它是否有效,请转到
Internet Explorer
(不是Chrome
或Firefox
)并输入testus:have_you_seen_this_man
这应该会触发你的.exe
(给你一些你想要这样做的提示 - 说是)并传递到 argstestus://have_you_seen_this_man
.
- To test if it works go to
Internet Explorer
(notChrome
orFirefox
) and entertestus:have_you_seen_this_man
this should fire your.exe
(give you some prompts that you want to do this - say Yes) and pass into argstestus://have_you_seen_this_man
.
这是要测试的示例控制台应用程序:
Here's sample console app to test:
using System;
namespace Testing
{
class Program
{
static void Main(string[] args)
{
if (args!= null && args.Length > 0)
Console.WriteLine(args[0]);
Console.ReadKey();
}
}
}
希望这可以为您节省一些时间.
Hope this saves you some time.
这篇关于如何在 Windows 中注册自定义 URL 协议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文