How do I create my own URL protocol? (e.g. so://...) [closed]
Asked Answered
E

8

242

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?

Embry answered 23/12, 2008 at 15:45 Comment(4)
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 protocolAbdication
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.Partible
See also: https://mcmap.net/q/119227/-how-do-i-register-a-custom-url-protocol-in-windows/45375Cady
If you are using python, you can install simpler and use register_protocol_handler.Magenmagena
P
235

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

Pickerel answered 23/12, 2008 at 15:51 Comment(14)
What about non-Windows OSes?Ealasaid
"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).Limann
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.Pickerel
Pluggable protocol handler is definitely a better choice.Phytogenesis
(Default) here means empty string. Don't take it literally.Luciferous
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.Partible
@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.Paucker
@Paucker 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.Partible
@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://.Duodiode
@KalZekdor No. See RFC 6068 - The 'mailto' URI Scheme; 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 (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.Partible
@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.Duodiode
here is a self contained example / solution: gist.github.com/aleksey-bykov/d7d2bc61adf2da519f6844db87e023faAccompaniment
You can also specify application name by adding: [HKEY_CLASSES_ROOT\your-protocol-name\Application] "ApplicationName"="Your Application Name"Blayze
You can also use [HKEY_CURRENT_USER\SOFTWARE\Classes\your-protocol-name] instead of [HKEY_CLASSES_ROOT\your-protocol-name] without admin priviledges.Blayze
F
60

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\""
Frentz answered 1/9, 2011 at 22:23 Comment(18)
how to call from explorer, what is the urlMalone
@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.Frentz
Actually I am asking about this question #24265792.Malone
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"Frentz
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.Malone
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.Mayoralty
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.Frentz
@Erwinus Imp's question wasn't hard to understand :PMariannmarianna
@Malone 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.Mariannmarianna
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.Partible
@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.Frentz
@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.Partible
@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.Frentz
@Malone 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.Sabella
only %1 matters, there is no way to specify in the url %2 and %3 etcAccompaniment
here is a self contained example / solution: gist.github.com/aleksey-bykov/d7d2bc61adf2da519f6844db87e023faAccompaniment
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 manyHoyos
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!Leningrad
A
41

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.

Atreus answered 23/12, 2008 at 16:4 Comment(3)
That's just an example of something to entice users to click on it.Atreus
please explain this: «because to do it reliably you can't do it in managed code and have to do it in C++»Exponential
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.Atreus
R
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.

Rancho answered 23/12, 2008 at 15:57 Comment(5)
Notwithstanding the technical details of how to make a protocol work in Windows - this is the most important answer. You shouldn't create a new URI scheme unless it's registered with IETF, or using an experimental namespace (like an X- prefix)Haver
@Haver why not? is it illegal?Kutaisi
@JuanPerez because otherwise it might clash with a registered URI scheme.Haver
@Haver interesting. me and many others I know use mqtt:// which isn't registered on the list.Kutaisi
@JuanPerez then someone ought to register it...Haver
D
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.

Despot answered 23/12, 2008 at 16:14 Comment(0)
C
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

Castera answered 23/12, 2008 at 15:50 Comment(0)
V
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.

Vandusen answered 23/12, 2008 at 15:50 Comment(0)
F
-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.

Fluviomarine answered 23/12, 2008 at 15:49 Comment(1)
-1: misguiding, uses inaccurate nomenclature and does not provide any real valueAbdication

© 2022 - 2024 — McMap. All rights reserved.