Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass in multiple file/folder paths via a right-click event (verb) to an executable?

Related:

How to add new items to right-click event on Folders and Files in Windows?

I added custom right-click verb to all files by adding registry keys to HKEY_CLASSES_ROOT\*. End result looks like this

HKEY_CLASSES_ROOT*\Shell\TestRightClick\Command

-------Default = c:\RightClickTest.exe "%1"

Problem: when selecting multiple files c:\RightClickTest.exe will be called several times(number of selected files)

What I need: pass-in multiple files paths to one executable

like image 913
Chicago Avatar asked Dec 01 '09 15:12

Chicago


People also ask

How do I click and drag multiple files?

Press and hold the Control Key (on the keyboard). While holding the Ctrl Key, select another file. Repeat step 2 until all the required files are selected. Note: It is important to keep the Ctrl Key pressed to ensure all files are highlighted.

How do you select multiple files in multiple folders?

Click the first file or folder, and then press and hold the Ctrl key. While holding Ctrl , click each of the other files or folders you want to select.

How do I select multiple files in a folder from a list of file names?

To select multiple files on Windows 10 from a folder, use the Shift key and select the first and last file at the ends of the entire range you want to select. To select multiple files on Windows 10 from your desktop, hold down the Ctrl key as you click on each file until all are selected.


2 Answers

If you're looking for a quick and dirty workaround, you can create a shortcut to your executable in '%AppData%\Microsoft\Windows\SendTo' Now you can select a bunch of files, right click, select Send To, and your application.

This will pass all the selected files as individual command line options to one instance of your application... keep in mind there is a 32767 character command line limit which will limit the number of files you can pass to your application using this method, and make sure your program wont' try to open files it doesn't know how to deal with. In the long run, Factor Mystic's method is way better.

like image 127
lowlevel Avatar answered Oct 24 '22 03:10

lowlevel


As I stated in the previous question, you're going to have to be intelligent about this inside your application. One instance of the program will be launched per file selected if you're not using a shell extension. Your general strategy could be this:

  1. When the application is launched with a file parameter (%1), check if any instance of the application are already running.
  2. If another instance is running, open some sort of Inter-Process Communication (IPC) channel to that application.
  3. Communicate the file parameter of this instance to the main instance.
  4. Write logic in the main program to address receiving this information as it's running.
like image 23
Factor Mystic Avatar answered Oct 24 '22 02:10

Factor Mystic