Brandon Osborne
Brandon Osborne

Reputation: 863

How do I create a "custom protocol" and map it to an application?

How would one go about creating a "custom protocol?" I know you can create a URL protocol by adding a number of registry entries to HKEY_CLASSES_ROOT, but that seems to only work in a browser. I need for it to work in Windows Explorer also.

I know that I can write a client/server sort of interface, but I think that is overkill for my client's needs (and budget).

Long story short...

It sounds fairly simple (or so I thought). Any ideas?

Thanks

Upvotes: 13

Views: 16316

Answers (2)

Jeff Mercado
Jeff Mercado

Reputation: 134881

You can create a custom protocol as long as you add a URL Protocol value of type REG_SZ to a class's key. It doesn't need an actual value, just needs to be present. Here's a simple example of an "Echo Protocol" I just created which works in Windows Explorer.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Classes\echo]
"URL Protocol"=""
@="Echo Protocol"

[HKEY_CURRENT_USER\SOFTWARE\Classes\echo\shell]

[HKEY_CURRENT_USER\SOFTWARE\Classes\echo\shell\open]

[HKEY_CURRENT_USER\SOFTWARE\Classes\echo\shell\open\command]
@="C:\\WINDOWS\\SYSTEM32\\CMD.EXE /Q /C (echo %1) && pause"

Then if you type in Windows Explorer (or Run menu) for the path:

enter image description here

enter image description here

It should even work from a browser as well, you'll just need to confirm like any other protocol: enter image description here enter image description here

It should run the command:

enter image description here

I've found it will also work in the keys HKCR and HKLM\Software\Classes too.

Upvotes: 19

Garett
Garett

Reputation: 16828

The Registering an Application to a URL Protocol article details the process. There is a utility on GitHub that can be used to register custom URL protocols. The source code is provided.

Upvotes: 6

Related Questions