How to Register a Custom URL Protocol in Windows
In this article
To register a custom URL protocol in Windows, you create a registry key under HKEY_CLASSES_ROOT (or HKEY_CURRENT_USER\Software\Classes) named after your protocol, set its default value to a friendly description, mark it as a URL protocol, and add a shell\open\command subkey whose default value points to the executable that should handle the link. Once registered, clicking a link like myapp://some/path will launch your program with that URL passed as an argument. This guide walks through the exact registry structure, the command-line syntax, and the common pitfalls that stop handlers from firing.
What You'll Need
- Administrator rights on the PC (or the ability to write to
HKEY_CURRENT_USER\Software\Classesfor a per-user registration). - The full path to the executable that will handle the protocol, for example
C:\Program Files\MyApp\myapp.exe. - Knowledge of how your app expects the URL to be passed (as a single argument or split into parts).
- Registry Editor (
regedit.exe) or a.regfile you can double-click.
Step-by-Step
- Decide on a protocol name. Pick a short, unique scheme such as
myapp. Avoid names already used by Windows or common apps (for examplehttp,https,mailto,ms-settings). The name is case-insensitive and must not contain spaces or slashes. - Open Registry Editor. Press
Win+R, typeregedit, and press Enter. Accept the User Account Control prompt. Registry changes are immediate; there is no save step, so back up first if you are unsure (File > Export). - Choose the registration scope. For all users, navigate to
HKEY_CLASSES_ROOT. For the current user only, navigate toHKEY_CURRENT_USER\Software\Classes. Per-user registration does not require administrator rights and is often preferable for testing. - Create the protocol key. Right-click the chosen root, select New > Key, and name it exactly your protocol (for example
myapp). - Set the display name. With the new key selected, double-click the
(Default)value and enter a friendly description such asMyApp Protocol. This text appears in some dialogs and is good practice even though it is not strictly required. - Add the URL Protocol marker. Right-click the protocol key, choose New > String Value, name it
URL Protocol(with the space), and leave its value empty. This tells Windows the key represents a protocol handler rather than a file type. - Create the command key. Right-click the protocol key, choose New > Key, and name it
shell. Insideshell, create another key namedopen. Insideopen, create a key namedcommand. - Set the command line. Select the
commandkey and double-click its(Default)value. Enter the full path to your executable in quotes, followed by a space and"%1". For example:"C:\Program Files\MyApp\myapp.exe" "%1". The%1placeholder is replaced with the full URL that was clicked. - Test the registration. Press
Win+Rand type your URL, for examplemyapp://hello, then press Enter. Windows should launch your executable and pass the URL as an argument. You can also test from a browser address bar or an HTML link. - Verify with a second test. If the first launch works, close the app and try again from a different source (a link in a document, a shortcut, or a command prompt using
start myapp://test). This confirms the handler is registered system-wide rather than only for one caller.
Common Mistakes
- Missing the
URL Protocolvalue. Without it, Windows treats the key as a file association and the link may not launch anything. - Unquoted executable path. Paths containing spaces (such as
C:\Program Files\...) must be wrapped in double quotes, or Windows will try to runC:\Program.exewith the rest as arguments. - Forgetting
%1. If the command line omits%1, your app launches but never receives the URL, so it cannot act on the link. - Wrong key hierarchy. The path must be
protocol\shell\open\command. A missingopenorcommandlevel breaks the chain. - Using a reserved scheme. Overwriting an existing protocol such as
httporms-settingscan break system features. Always use a unique name. - Registering under the wrong hive. A key under
HKEY_CLASSES_ROOTaffects all users and needs admin rights; a key underHKEY_CURRENT_USER\Software\Classesaffects only you. Mixing them up leads to "works for me but not for others" confusion.
Tips
- Use a
.regfile for repeatable installs. Export your working key (right-click > Export) and ship it with your app; double-clicking merges it into the registry. - Keep the protocol name lowercase and short. Browsers and shells handle it consistently, and it is easier to type in tests.
- If your app needs the URL split into parts, pass
%1and parse it inside the app rather than trying to split it in the registry command line. - Test with a non-privileged user account if you registered per-user, and with a standard user if you registered system-wide, to confirm the scope behaves as expected.
- Document the protocol in your app's help so users know what links look like and which app should open them.
Troubleshooting
If clicking a link does nothing, first confirm the key path is exactly protocol\shell\open\command and that the (Default) value of command contains the quoted executable plus %1. Then check that the URL Protocol string value exists and is empty. If the app launches but ignores the URL, verify your app reads the first command-line argument; many apps expect the URL as argv[1]. If Windows shows a "How do you want to open this?" dialog, the protocol key is likely missing or malformed. If the handler works in one browser but not another, test with a plain Win+R run first to isolate whether the issue is the registration or the browser's handling of external protocols. If you registered under HKEY_CLASSES_ROOT but are testing as a different user, confirm the key is visible there; otherwise register under HKEY_CURRENT_USER\Software\Classes for that user. Finally, if you previously registered the same name, delete the old key before adding the new one to avoid stale command lines. Restarting Explorer or signing out and back in can help if the shell has cached the old association.
Frequently Asked Questions
Do I need administrator rights to register a custom URL protocol?
Only if you write to HKEY_CLASSES_ROOT, which affects all users. Writing to HKEY_CURRENT_USER\Software\Classes registers the protocol for your user account without elevation.
Can I use an existing protocol name like http?
You should not. Overwriting a system protocol can break links and features that depend on it. Always choose a unique scheme.
Why does my app open but not receive the URL?
The command line probably lacks %1, or the app does not read its first argument. Add "%1" after the quoted executable path and confirm the app parses the argument.
Does the protocol name have to be lowercase?
No. Windows treats protocol names case-insensitively, but lowercase is conventional and easier to test.
How do I remove a custom protocol?
Delete the protocol key you created (for example myapp) from the same location where you registered it. The association disappears immediately.
Can I register a protocol for a script instead of an executable?
Yes, as long as the command line points to something Windows can launch, such as a .bat or .cmd file, and that script handles the URL argument. Keep the path quoted if it contains spaces.