如何在 Windows 中注册自定义 URL 协议? [英] How do I register a custom URL protocol in Windows?

查看:79
本文介绍了如何在 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?

推荐答案

  1. 转到Start然后在Find中输入regedit ->它应该打开Registry editor

  1. Go to Start then in Find type regedit -> it should open Registry editor

HKEY_CLASSES_ROOT上点击鼠标右键,然后New -> Key

Click Right Mouse on HKEY_CLASSES_ROOT then New -> Key

  1. 在 Key 中给出你想要调用 url 的小写名称(在我的例子中是 testus://sdfsdfsdf)然后点击 Right Mousetestus -> 然后 New -> String Value 并添加不带值的 URL protocol.
  1. 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 on testus -> then New -> String Value and add URL protocol without value.

  1. 然后像使用协议一样添加更多条目( Right Mouse New -> Key )并创建像 testus<这样的层次结构/code> -> shell -> open -> command 并在 command 内部更改 (默认) 到您要启动的 .exe 所在的路径,如果您想将参数传递给您的 exe,则将 exe 的路径包裹在 "" 中并添加 <代码>"%1" 看起来像:"c:\testing\test.exe" "%1"
  1. Then add more entries like you did with protocol ( Right Mouse New -> Key ) and create hierarchy like testus -> shell -> open -> command and inside command 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"

  1. 要测试它是否有效,请转到 Internet Explorer(不是 ChromeFirefox)并输入 testus:have_you_seen_this_man 这应该会触发你的 .exe(给你一些你想要这样做的提示 - 说是)并传递到 args testus://have_you_seen_this_man.
  1. To test if it works go to Internet Explorer (not Chrome or Firefox) and enter testus: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 args testus://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屋!

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