I've seen dozens of tutorials and posts about adding an app to the context menu when you right-click on your desktop, but that's not what I want. I need a .bat command that adds an "Open with {myapphere}" item to any file I right-click on (but not folder). I'm looking for an action like "Scan with Avast antivirus" or "Add to .rar archive", and I need a REG command that creates it. Is it possible?
Also, how will my script get the file location?
Thanks
2 Answers
For a simple way without using directly regedit you can use the very well made tool FileTypesMan (FileTypesMan64 for 64bit systems), freeware: http://www.nirsoft.net/utils/file_types_manager.html
NB: if you want to directly write a reg file, go to the end of this answer.
There, you go down the list to select the * extension to add an action that will be available for any file.
On the lower part, you see the already existing actions:
- Right-click and choose "new action". Enter a name, and the caption you want to display in the menu : "Open with {myapphere}"
- Fill-in the command-line : Browse for you app or enter directly its path, e.g "C:\Program Files\myapppath\myapp.exe" "%1" (keep the double-quotes). The "%1" will be replaced by the location of the selected file by explorer.
- [optional] You can check the "extended" checkbox to display this menu entry only when you shift-right-click on your file in explorer.
To get a .reg file that you can reuse for doing this, right-click on the action you just created and select "Open Action in RegEdit".
There, in Regedit, right-click on the command folder and select "export". Provide a name for the reg file, and you have it (You can then edit it to modify it or add other file type handlings if you wish):
Contents of the .reg file :
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT*\shell\Open with myapp\command]
@=""C:\Program Files\myapppath\myapp.exe" "%1""
-
thank you so much! but how does the app launched get the file location?– BiskweetCommented Jun 30, 2020 at 17:05
-
Explorer transmits the path of the file to the action via the %1 parameter. I edit my post and replace the sentence "The "%1" will represent the location of the file selected in explorer." by "The "%1" will be replaced by the location of the selected file by explorer." to better explain this.– GazeldCommented Jul 2, 2020 at 13:47
-
What if multiple files are selected? Are they in %2, %3, etc.? If so, how do you account for the fact that there could be an arbitrary number of files selected, even thousands?– MichaelCommented Oct 27, 2022 at 23:57
-
If you select multiple files, each will be called separately, as if you right-clicked each one individually.– GazeldCommented Oct 31, 2022 at 0:21
This is a list of special file types:
**Type Description**
.* All Files
Unknown All files that aren’t defined
Folder All Folders including those that aren’t directories
Directories All Directories
Drive All Disk Drives
AllFileSystemObjects Everything you can see in Explorer
AllFileSystemEditObjects Everything you can see in Explorer that can be edited.
So HKCR\.*
. If only a user add to HKCU\Software\Classes\.*
.
From Windows 98 so the MSDos text editor is no longer available.
This adds a command Binary View to all file types. This starts the MS–Dos text editor in binary mode at 78 characters wide (/78), in read only mode (/r), and in 43 or 50 line display (/h)
REGEDIT4
[HKEY_CLASSES_ROOT\*\Shell\BinaryView]
@="&Binary View"
[HKEY_CLASSES_ROOT\*\Shell\BinaryView\command]
@="C:\\windows\\command\\Edit.com /78 /r /h \"%1\""