pythonwindowsregistrywindows-shell

How do I add a new item to the context menu for .url file types?


When adding a custom option to the context menu for different types of icons, this code works fine:

with reg.CreateKey(reg.HKEY_CURRENT_USER, base_path) as main_key:
    reg.SetValueEx(main_key, 'MUIVerb', 0, reg.REG_SZ, 'New Item')
    with reg.CreateKey(main_key, 'command') as cmd_key:
        reg.SetValue(cmd_key, '', reg.REG_SZ, r'"C:\...\app.exe" "%1"')

For file types like .txt, .png, etc., I used: base_path = "SOFTWARE\\Classes\\*\\shell\\NewItem" For folders: base_path = "SOFTWARE\\Classes\\Directory\\shell\\NewItem" For .lnk files: base_path = "SOFTWARE\\Classes\\lnkfile\\shell\\NewItem" What base_path should I use for Internet Shortcuts (.url files)? Is there a way to add new item for context menues for Internet Shortcuts? I need the item add only for HKEY_CURRENT_USER.

I’ve tried:

base_path = "SOFTWARE\\Classes\\InternetShortcut\\shell"
// And
base_path = "SOFTWARE\\Classes\\.url\\shell\\NewItem"

but that didn’t help


Solution

  • The systemwide list of registered filetypes is located in HKEY_CLASSES_ROOT (since Windows 3 or NT 3.5 I think, so this is one of the oldest parts of the registry).

    You were working in the user specific part in HKEY_CURRENT_USER\Software\Classes, this is just complementing / overriding the systemwide part.

    You can read the actual registry values with regedit.exe, but as a non-admin user you are not allowed to overwrite certain parts.

    For your special case (.url extension) I didn't find a user specific entry on my system, just a systemwide entry, and that is probably the reason you got stuck.

    You can override the systemwide entry per user, the class is InternetShortcut - I just don't know you if you

    If you add results you find maybe as comments, I can update this answer for future reference.