How to register my own URL protocol in Windows?

How to register a user protocol in Windows so that when I click a link in an email or on a web page, my application is opened and the parameters from the URL are passed to it?

+39
windows url protocols
Sep 17 '08 at 6:57
source share
3 answers

I think this is described on MSDN, see Registering an Application in the URL Protocol .

+22
Sep 17 '08 at 7:01
source share
β€” -

The MSDN link is good, but the security information is not complete there. Handler registration should contain "% 1", not% 1. This is a security measure because some URL sources do not decode% 20 correctly before calling your custom protocol handler.

PS. You will get the entire URL, not just the URL parameters. But the URL may be subject to some mishandling, in addition to the conversion of 20-20% space already mentioned. This helps to be conservative in URL syntax design. Do not accidentally throw // or you get in a mess in this file: // is.

+18
Sep 17 '08 at 10:48
source share
  • Go to Start , then in Find type regedit β†’ to open the Registry editor

  • Press Right Mouse on HKEY_CLASSES_ROOT , then New β†’ Key

enter image description here

  1. In the key key, specify the lower case name by which you want to name the URLs (in my case it will be testus://sdfsdfsdf ), then click the Right Mouse on testus β†’, then New β†’ String Value and add the URL protocol without a value.

enter image description here

  1. Then add other entries similar to the protocol ( Right Mouse New β†’ Key ) and create a hierarchy like testus β†’ shell β†’ open β†’ command and inside the command change (Default) to the path where the .exe you want to run is if you want pass the parameters to exe, then wrap the path to exe in "" and add "%1" to look like this: "c:\testing\test.exe" "%1"

enter image description here

  1. To check if it works, go to Internet Explorer (not Chrome or Firefox ) and type testus:have_you_seen_this_man , this should trigger your .exe (give some hints you want to do), say β€œYes”) and go to args testus://have_you_seen_this_man .

Here is an example console application for testing:

 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.

+8
Jul 05 '16 at 14:26
source share



All Articles