Skip to content

Instantly share code, notes, and snippets.

@nuvious
Created January 15, 2026 18:16
Show Gist options
  • Select an option

  • Save nuvious/288515cc32373da5dc01d6d1ca43cbac to your computer and use it in GitHub Desktop.

Select an option

Save nuvious/288515cc32373da5dc01d6d1ca43cbac to your computer and use it in GitHub Desktop.
Custom Windows Protocol Handler Registration with Python (No Admin Required)
"""
This registers a simple echo protocol handler so that echo://anything_here will
open a command prompt and echo the full URL.
This does not require admin privileges as it writes to HKEY_CURRENT_USER.
Built from the following reference:
https://stackoverflow.com/questions/3964152/how-do-i-create-a-custom-protocol-and-map-it-to-an-application/3964401#3964401
"""
import winreg
import webbrowser
# Base registry path for the echo protocol
ECHO_BASE = r"SOFTWARE\Classes\echo"
def apply_echo_protocol_registry():
"""
Generates the registry entries to register the echo:// URL protocol handler.
"""
# [HKEY_CURRENT_USER\SOFTWARE\Classes\echo]
with winreg.CreateKeyEx(
winreg.HKEY_CURRENT_USER,
ECHO_BASE,
0,
access=winreg.KEY_SET_VALUE,
) as key:
# "URL Protocol"=""
winreg.SetValueEx(key, "URL Protocol", 0, winreg.REG_SZ, "")
# @="Echo Protocol" (default value)
winreg.SetValueEx(key, "", 0, winreg.REG_SZ, "Echo Protocol")
# [HKEY_CURRENT_USER\SOFTWARE\Classes\echo\shell]
winreg.CreateKeyEx(winreg.HKEY_CURRENT_USER, ECHO_BASE + r"\shell", 0)
# [HKEY_CURRENT_USER\SOFTWARE\Classes\echo\shell\open]
winreg.CreateKeyEx(winreg.HKEY_CURRENT_USER, ECHO_BASE + r"\shell\open", 0)
# [HKEY_CURRENT_USER\SOFTWARE\Classes\echo\shell\open\command]
with winreg.CreateKeyEx(
winreg.HKEY_CURRENT_USER,
ECHO_BASE + r"\shell\open\command",
0,
access=winreg.KEY_SET_VALUE,
) as key:
# @="C:\\WINDOWS\\SYSTEM32\\CMD.EXE /Q /C (echo %1) && pause"
command = r'C:\WINDOWS\SYSTEM32\CMD.EXE /Q /C (echo %1) && pause'
winreg.SetValueEx(key, "", 0, winreg.REG_SZ, command)
if __name__ == "__main__":
print("Applying echo:// protocol handler registry entries.")
apply_echo_protocol_registry()
print("Opening echo://Hello_World! to test the protocol handler.")
webbrowser.open("echo://Hello_World!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment