Created
February 25, 2023 14:23
-
-
Save dario61081/5c5372b44674dc9a7f25c2394cc09492 to your computer and use it in GitHub Desktop.
Register/Unregister protocol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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