Skip to content

Instantly share code, notes, and snippets.

@dario61081
Created February 25, 2023 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dario61081/5c5372b44674dc9a7f25c2394cc09492 to your computer and use it in GitHub Desktop.
Save dario61081/5c5372b44674dc9a7f25c2394cc09492 to your computer and use it in GitHub Desktop.
Register/Unregister protocol
class RegisterProtocol:
@staticmethod
def register(protocol_key, command):
location = winreg.HKEY_CLASSES_ROOT
key = winreg.CreateKey(location, protocol_key)
winreg.SetValue(key, "URL Protocol", winreg.REG_SZ, "")
key = winreg.CreateKey(location, protocol_key + "\\shell\\open\\command")
winreg.SetValue(key, None, winreg.REG_SZ, command + " %1")
@staticmethod
def unregister(protocol_key):
location = winreg.HKEY_CLASSES_ROOT
winreg.DeleteKey(location, protocol_key + "\\shell\\open\\command")
winreg.DeleteKey(location, protocol_key + "\\shell\\open")
winreg.DeleteKey(location, protocol_key + "\\shell")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment