239

I have seen:

  • http://www...
  • ftp://blah.blah...
  • file://blah.blah...
  • unreal://blah.blah...
  • mailto://blah.blah...

What is that first section where you see http and the like called?

Can I register my own?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Michael Beck
  • 2,806
  • 3
  • 20
  • 22
  • 20
    The correct name is "scheme" (see RFC 2616 and 2396). Even if many URL schemes are named after protocols, this does not imply that the only way to access the resource is via the protocol – Marek Nov 09 '10 at 11:48
  • 1
    There are two types of protocols but I don't know what term to use to differentiate them. The "file" and "mailto" protocols are processed in the client. The "http" and "ftp" protocols are processed in the server. At first I was confused by the answers for protocols processed in the browser when I want something that is processed in the server. – Sam Hobbs Apr 05 '17 at 21:15
  • See also: https://stackoverflow.com/q/80650/45375 – mklement0 Aug 31 '22 at 20:49
  • If you are using python, you can install [simpler](https://pypi.org/project/simpler/) and use [register_protocol_handler](https://simpler.readthedocs.io/en/latest/simpler.terminal.html#simpler.terminal.register_protocol_handler). – Carlos Roldán Oct 27 '22 at 23:13

8 Answers8

232

The portion with the HTTP://,FTP://, etc are called URI Schemes

You can register your own through the registry.

HKEY_CLASSES_ROOT/
  your-protocol-name/
    (Default)    "URL:your-protocol-name Protocol"
    URL Protocol ""
    shell/
      open/
        command/
          (Default) PathToExecutable

Sources: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml, http://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx

PsychoData
  • 1,198
  • 16
  • 32
James Gregory
  • 14,173
  • 2
  • 42
  • 60
  • 23
    What about non-Windows OSes? – Bdoserror Dec 23 '08 at 17:04
  • 10
    "What about non-Windows OSes?" It's application-specific. I think it's actually frequently application-specific on Windows too (this won't make everything magically work). – Calum Dec 23 '08 at 17:19
  • 3
    Define everything. The registry entry tells Windows to pass the Uri with that protocol to the application specified, everything else should be handled by the application itself. – James Gregory Dec 23 '08 at 19:32
  • 5
    Pluggable protocol handler is definitely a better choice. –  Dec 01 '09 at 17:17
  • 8
    `(Default)` here means empty string. Don't take it literally. – deerchao Apr 05 '13 at 09:02
  • Does that include protocols such as "http" and "ftp" that are processed in the server? If so then the important part is how to write the executable. – Sam Hobbs Apr 05 '17 at 21:16
  • @user34660 "http" and "ftp" already have pretty good executables for handling those schemes. 'Google Chrome' is a good example of a program that will handle those ones well. – Hicsy Sep 15 '17 at 01:12
  • @Hicsy I said "like" http and ftp but I did not mean them specifically. The point I was implying is that there are two types of protocols. The mailto protocol is handled in the client only whereas http and ftp go out to the server and back. People seem to be treating them as the same but I doubt that if we wanted to add (as in **develop**) a protocol that goes from the client to the server that we only need to add a registry entry in the client without any code or anything in the server. – Sam Hobbs Sep 16 '17 at 22:31
  • @user34660 As far as Windows is concerned, they are the same thing. http is associated in windows with a local program, namely a web browser. It's the web browser that handles the actual outgoing request using the http specification. All the handler is doing is telling windows "This program knows what to do with URIs of this type." It's the same whether we're talking `http://`, `mailto://`, `tel://`, or, I dunno, `fish://`. – Kal Zekdor Mar 16 '18 at 00:12
  • @KalZekdor No. See [RFC 6068 - The 'mailto' URI Scheme](https://tools.ietf.org/html/rfc6068); the word _server_ appears twice, once in reference to http and again saying mailto is unusual because it does not cause an immediate interaction with a server. The standard is totally empty of anything happening server-side. Also see [Hypertext Transfer Protocol -- HTTP](https://tools.ietf.org/html/rfc2616) (not the most current but useful here); it has the word _server_ more than 600 times. For http there is a server-side portion. Most protocols need server-side software that is not described here. – Sam Hobbs Mar 16 '18 at 07:24
  • 4
    @user34660 You are confusing "schemes" and "handlers". There is a specification of a `mailto:` URI scheme, but that has *nothing* to do with the registration of a handler for URIs of the `mailto:` scheme. The OS simply doesn't care, it's the program that handles the scheme that does all of that. Windows treats all URIs in exactly the same way, at least insofar as I know, it passes along the URI as an argument to the specified handler program. – Kal Zekdor Mar 16 '18 at 22:55
  • here is a self contained example / solution: https://gist.github.com/aleksey-bykov/d7d2bc61adf2da519f6844db87e023fa – Trident D'Gao May 11 '18 at 23:59
  • You can also specify application name by adding: `[HKEY_CLASSES_ROOT\your-protocol-name\Application]` `"ApplicationName"="Your Application Name"` – Bohdan Aug 30 '22 at 15:32
  • You can also use `[HKEY_CURRENT_USER\SOFTWARE\Classes\your-protocol-name]` instead of `[HKEY_CLASSES_ROOT\your-protocol-name]` without admin priviledges. – Bohdan Aug 30 '22 at 15:35
58

Open notepad and paste the code below into it. Change "YourApp" into your app's name.

Save it to YourApp.reg and execute it by clicking on it in explorer.

That's it!

REGEDIT4

[HKEY_CLASSES_ROOT\YourApp]
@="URL:YourApp Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\YourApp\DefaultIcon]
@="\"C:\\Program Files\\YourApp\\YourApp.exe\""

[HKEY_CLASSES_ROOT\YourApp\shell]

[HKEY_CLASSES_ROOT\YourApp\shell\open]

[HKEY_CLASSES_ROOT\YourApp\shell\open\command]
@="\"C:\\Program Files\\YourApp\\YourApp.exe\" \"%1\" \"%2\" \"%3\" \"%4\" \"%5\" \"%6\" \"%7\" \"%8\" \"%9\""
gre_gor
  • 6,669
  • 9
  • 47
  • 52
Codebeat
  • 6,501
  • 6
  • 57
  • 99
  • 2
    how to call from explorer, what is the url – imp Jun 17 '14 at 10:27
  • @imp, it is not a smart idea to call .reg files from (internet) explorer. You can use the start command to execute a reg file, like 'start yourregfile.reg' but you will get a prompt message from the os to be sure to add it to the registry. To able to this the user must have admin privileges. – Codebeat Jun 18 '14 at 01:05
  • 1
    Actually I am asking about this question http://stackoverflow.com/questions/24265292/how-to-pass-argument-through-custom-url-to-an-application. – imp Jun 18 '14 at 05:41
  • 3
    The %1 %2 etc. in the reg file are the argument(s) for your app. So if you do YourApp.exe "your argument" so %1 == "your argument" – Codebeat Jun 18 '14 at 05:45
  • please see question, I added image of registry. I am asking about url that I have to type in explorer along with filename as argument. – imp Jun 18 '14 at 05:52
  • Hi @Erwinus. I am wondering whether this line `@="URL:YourApp Protocol"` is an optional one? I have problem in IE 11 on Win 7 SP1, in which my custom URL protocol having problem, where it runs just fine in any other browser+windows version. – swdev Jul 06 '14 at 23:01
  • YourApp Protocol is the name of your protocol. For example: SwDev Protocol. "URL Protocol" is the name of the protocol, for example: swdev. So you can do for example: swdev://anything-you-like. If there is a problem with IE, it can caused by the local internet security settings because you are using an unknown not default protocol name. – Codebeat Jul 07 '14 at 23:17
  • @Erwinus Imp's question wasn't hard to understand :P – iautomation Sep 13 '15 at 10:33
  • @imp In Google Chrome, parameters are parsed like such: protocol:"param1 param2". I hope this helps someone. Otherwise, from my tests it seems that the entire url will be passed as parameter 1. You then have to use the program to parse that. This is how magnet links work with BT as well. – iautomation Sep 13 '15 at 14:06
  • Does that include protocols such as "http" and "ftp" that are processed in the server? If so then the important part is how to write the executable. – Sam Hobbs Apr 05 '17 at 21:20
  • @user34660: Well, give it try/go and share it here. I guess these are already taken by IE and I think you get some security warnings. – Codebeat Apr 06 '17 at 12:14
  • @Erwinus, when I said _such as "http" and "ftp"_ I meant _like_ but not those specifically. Some protocols are processed in the server and some in the client. People are talking about both types as being the same. – Sam Hobbs Apr 06 '17 at 17:20
  • @user34660: It can be anything you want. For example itunes://myapp like itunes uses when installed. I don't use itunes (hate it), but can rermember it was something like that to associate the online app library with itunes installed on your computer. When Apple checks for this protocol with javascript they can figure out itunes is installed. That's why a webpage that is totally seperated from the system can decide to serve you the app-link or the link to install itunes. – Codebeat Apr 06 '17 at 22:57
  • @imp to get the effect you asked for, you just need to create the file in this post and customize it a little. after you run the `.reg file` *one time* it will tell the system to use your app when you type in that protocol. Just to repeat, you only need to run this code once per system to register your app to the protocol. – That Realty Programmer Guy May 19 '17 at 05:42
  • 5
    only %1 matters, there is no way to specify in the url %2 and %3 etc – Trident D'Gao May 11 '18 at 22:46
  • here is a self contained example / solution: https://gist.github.com/aleksey-bykov/d7d2bc61adf2da519f6844db87e023fa – Trident D'Gao May 11 '18 at 23:59
  • here is calling write following text in internet explore url YourApp:"testParm" YourApp is the URL scheme you defined "testParm" parameter can be one of many – Haseeb Jan 23 '19 at 08:40
  • 1
    https://gist.github.com/aleksey-bykov/d7d2bc61adf2da519f6844db87e023fa is broken - does anyone have a full self-contained example of a URL and a custom protocoll handler where not the entire URI is used, but one parameter? I have the following: a.exe xxx param1 yyy which I want to have executed via mycust://param1 or similar Thanks in advance! – J S Feb 16 '20 at 10:25
40

This is different for each browser, in IE and windows you need to create what they call a pluggable protocol handler.

The basic steps are as follows:

  1. Implement the IInternetProtocol interface.
  2. Implement the IInternetProtocolRoot interface.
  3. Implement the IClassFactory interface.
  4. Optional. Implement the IInternetProtocolInfo interface. Support for the HTTP protocol is provided by the transaction handler.
  5. If IInternetProtocolInfo is implemented, provide support for PARSE_SECURITY_URL and PARSE_SECURITY_DOMAIN so the URL security zone manager can handle the security properly. Write the code for your protocol handler.
  6. Provide support for BINDF_NO_UI and BINDF_SILENTOPERATION.
  7. Add a subkey for your protocol handler in the registry under HKEY_CLASSES_ROOT\PROTOCOLS\Handler.
  8. Create a string value, CLSID, under the subkey and set the string to the CLSID of your protocol handler.

See About Asynchronous Pluggable Protocols on MSDN for more details on the windows side. There is also a sample in the windows SDK.

A quick google also showed this article on codeproject: http://www.codeproject.com/KB/IP/DataProtocol.aspx.

Finally, as a security guy I have to point out that this code needs to be battle hardened. It's at a high risk because to do it reliably you can't do it in managed code and have to do it in C++ (I suppose you could use VB6). You should consider whether you really need to do this and if you do, design it carefully and code it securely. An attacker can easily control the content that gets passed to you by simply including a link on a page. For example if you have a simple buffer overflow then nobody better do this: <a href="custom:foooo{insert long string for buffer overflow here}"> Click me for free porn</a>

Strongly consider using strsafe and the new secure CRT methods included in the VC8 and above compilers. See http://blogs.msdn.com/michael_howard/archive/2006/02/27/540123.aspx if you have no idea what I'm talking about.

Peter Oehlert
  • 16,368
  • 6
  • 44
  • 48
  • 7
    That's just an example of something to entice users to click on it. – Peter Oehlert Dec 23 '08 at 20:19
  • please explain this: «because to do it reliably you can't do it in managed code and have to do it in C++» – LogicDaemon Apr 23 '15 at 06:26
  • 2
    This is from .Net 2.0 runtime (note, this included 3.0 and 3.5) timeframe. It didn't support different CLR runtimes in the same process, so if I wrote a 1.0 handler and you wrote a 2.0 one, and both of our products were installed on a customers computer, together we'd insure that the browser crashes every time it launched. The 4.0 runtime tried to target this issue but my recollection is there were still boundary cases to be concerned about. But the gist is using .Net objects for plugins in native processes was to be absolutely avoided before 4.0 and may still have corner cases to worry about. – Peter Oehlert Apr 23 '15 at 13:21
19

Here's a list of the registered URI schemes. Each one has an RFC - a document defining it, which is almost a standard. The RFC tells the developers of new applications (such as browsers, ftp clients, etc.) what they need to support. If you need a new base-level protocol, you can use an unregistered one. The other answers tell you how. Please keep in mind you can do lots of things with the existing protocols, thus gaining their existing implementations.

Yuval F
  • 20,565
  • 5
  • 44
  • 69
4

For most Microsoft products (Internet Explorer, Office, "open file" dialogs etc) you can register an application to be run when URI with appropriate prefix is opened. This is a part of more common explanation - how to implement your own protocol.

For Mozilla the explanation is here, Java - here.

Dmitry Khalatov
  • 4,313
  • 3
  • 33
  • 39
3

It's called the protocol. The only thing that prevents you from making your own protocol is you have to:

  1. Write a browser or user agent of some kinds that understands that protocol, both in its URL form and in the actual data format
  2. Write a server that understands that protocol
  3. Preferably, have a specification for the protocol so that browser and server can continue to work together.

Windows makes #1 really easy, an in many cases this is all you actually need. Viz:

Registering an Application to a URL Protocol

JSBձոգչ
  • 40,684
  • 18
  • 101
  • 169
1

The first section is called a protocol and yes you can register your own. On Windows (where I'm assuming you're doing this given the C# tag - sorry Mono fans), it's done via the registry.

Powerlord
  • 87,612
  • 17
  • 125
  • 175
GaryF
  • 23,950
  • 10
  • 60
  • 73
-12

You don't really have to do any registering as such. I've seen many programs, like emule, create their own protocol specificier (that's what I think it's called). After that, you basically just have to set some values in the registry as to what program handles that protocol. I'm not sure if there's any official registry of protocol specifiers. There isn't really much to stop you from creating your own protocol specifier for your own application if you want people to open your app from their browser.

Kibbee
  • 65,369
  • 27
  • 142
  • 182