Register your own Protocol Scheme to handle custom URLs

Have you ever wanted to register your own protocol scheme to handle custom URLs? No? Oh.

Well, if you did want to do that it turns out that it's easier than you might have thought. Essentially it's just the same as associating a file type with an application.

Here's an example reg file:

Windows Registry Editor Version 5.00

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

"URL Protocol"=""

[HKEY_CLASSES_ROOT\myUrl\shell]

[HKEY_CLASSES_ROOT\myUrl\shell\open\command]
@="\"C:\\Program Files\\MyAppFolder\\MyApp.exe\" \"%1\""

Now when you click a link such as myUrl://123456 it will be passed as a command line argument to MyApp.exe

Of course MyApp.exe needs to know to handle such urls in its command line, but you could implement your own RESTful navigation system, such as this:

myUrl://12345678-00000004/view/order/569/4

Which could open the customer record for customer 12345678-00000004, then display order 569, item 4.

One last thing to note, if you want to paste them into Outlook you need to prefix them with url:

url: myUrl://12345678-00000004/view/order/569/4

which is fairly ugly, or if you're using HTML:

<a href="myurl://12345678-00000004/view/order/569/4">myUrl://12345678-00000004/view/order/569/4</a>

Nifty!

Comments