3

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

1 Answer 1

3

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

  • also have to override the .URL extension (not the all CAPS in the name) per user
  • have to copy over the systemwide entries of InternetShortcut and extend them with your own or
  • can just add the wanted entries as user specific setting to a (newly created) InternetShortcut registry key.

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

Sign up to request clarification or add additional context in comments.

5 Comments

What are the InternetShortcut systemwide entries, and how can I safely copy them?
You find them at HKEY_CLASSES_ROOT\InternetShortcut - I think they could vary from OS version to OS version and maybe also depending on the configured browser. For your current system you can look them up with regedit.exe, but I'm sorry that I don't know how to read them with Python, probably you will find help in answers to this other SO question: stackoverflow.com/questions/5227107/…
,I manually exported the relevant registry keys from regedit.exe and added them under HKEY_CURRENT_USER. Then, I added a new entry under the shell key for both InternetShortcut and .url, creating a NewItem key at a path "HKEY_CURRENT_USER\SOFTWARE\Classes\...\shell\NewItem" , but this didn't work. Did you mean for me to do this, or I have done something wrong?
yes I meant this and it would be sufficient for the InternetShortcut key - it is then automatically integrated into the HKEY_CLASSES_ROOT part. But as for other file types the entries just appear in the "open with" menu, and this is not available by default for the InternetShortcut, you won't see them. I found instructions how to enable it, but unfortunately you have to use administrative rights: elevenforum.com/t/…
Thanks! This solution will work fine for most systems, but it can give error depending on the .url file's ProgId. The ProgId value is stored in the registry at the following path: [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.url\UserChoice] "ProgId" = "Your Value" In my case, the ProgId was IE.AssocFile.URL, but it could also be something like ChromeHTML, FirefoxURL, OperaHTML, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.