Add a Windows Shell context menu entry for a specific extension (not file type)
Asked Answered
E

1

12

To add a Windows shell context menu, let's say for .txt files - if the .txt extension in HKEY_CLASSES_ROOT (or in HKEY_CURRENT_USER\Software\Classes, doesn't really matter) has the default value (file type) txtfile - you add the command to HKEY_CLASSES_ROOT\txtfile\shell\yourcommand (and the command itself in HKEY_CLASSES_ROOT\txtfile\shell\yourcommand\command, of course) and there you go.

However, let's say the .txt extension instead has the default value Notepad++_file. Notepad++_file might be the file type for many other extensions, so if you add the command to HKEY_CLASSES_ROOT\Notepad++_file, then this command will appear for every extension associated with Notepad++.

So, the question is: how can you add a menu entry for ONLY ONE specific EXTENSION, without changing its file type, if possible at all?

P.S.: I don't want to just duplicate the file type, because future changes to the original file type won't affect the duplicated one.

Emperor answered 26/1, 2014 at 11:39 Comment(1)
Apparently, the cleanest way these days is the HKEY_CLASSES_ROOT\SystemFileAssociations\.extension key.Lend
O
28

Here you go:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\your custom app]
@="Open with your custom app"
"icon"="C:\\Windows\\notepad.exe,0"
"AppliesTo"=".nfo"

[HKEY_CLASSES_ROOT\*\shell\your custom app\command]
@="C:\\Windows\\notepad.exe \"%1\""

The line "AppliesTo"=".nfo" does the trick.

Works perfectly on Windows 10.

It works per file extension, regardless if there is an application associated with that extension or not. Doing this way it less invasive and leaves a very small footprint in the registry.

Compare to Add menu item to windows context menu only for specific filetype


Edit:

If you want to apply that command to more than one extension use:

"AppliesTo"="System.FileName:\"*.nfo\" OR System.FileName:\"*.log\""

Credit: https://superuser.com/questions/183785/windows-7-context-menu-for-folders-if-folder-contains-certain-filetypes

Orfurd answered 2/1, 2016 at 23:2 Comment(5)
The ability to apply multiple criteria you provided is a life saver!!Luminesce
can I add a shortcut to this menu item, so I can select file and press a shortcut to edit selected file?Membranophone
To only check extensions this is simpler: "AppliesTo"="System.FileExtension:=.nfo OR System.FileExtension:=.log"Speciation
PS: "AppliesTo"=".nfo" isn't the same because it include also: file1.nfox, file2.nfoy, etc.Speciation
Thanks for this. Also you can just do .jpg OR .png OR .gif etc in the applies to bitInterpenetrate

© 2022 - 2024 — McMap. All rights reserved.