Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

  • A third-party application should call: tbwx:<row_id>
  • My app should load and delete a record from the database.

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

Thanks

like image 935
Brandon Osborne Avatar asked Oct 18 '10 23:10

Brandon Osborne


People also ask

What is a custom protocol link?

A very practical version of an Action Menu Item (AMI) is a variant that will run an application or a script on your local computer. For this to work you need to set up a connection between your browser and the script or application you wish to run. This link is called a custom browser protocol.


2 Answers

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_CLASSES_ROOT\echo]
"URL Protocol"=""
@="Echo Protocol"

[HKEY_CLASSES_ROOT\echo\shell]

[HKEY_CLASSES_ROOT\echo\shell\open]

[HKEY_CLASSES_ROOT\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 HKCU\Software\Classes and HKLM\Software\Classes too. It isn't listed in the Control Panel\Programs\Default Programs\Set Associations list however. Other keys might need to be updated or it would have to be registered with Windows somehow.

This seems to continue to work all the way up to Windows 10 and possibly 11.

like image 196
Jeff Mercado Avatar answered Oct 26 '22 14:10

Jeff Mercado


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.

like image 45
Garett Avatar answered Oct 26 '22 15:10

Garett