41

Passing a single filename to a context menu shell command is simple:

[HKEY_CLASSES_ROOT\*\shell\MyProgram\Command]
@="program.exe %1"

But if I select multiple files, program.exe is invoked for each such selected file.

What I would like to do instead is invokeprogram.exe only once, passing to it all the filenames currently selected.

How to do this?

Revious
  • 7,816
  • 31
  • 98
  • 147
WinWin
  • 7,493
  • 10
  • 44
  • 53
  • 1
    I've successfully added an item to file context-menu (`HKEY_CLASSES_ROOT\*\shell`). The item shows up when I right-click on a file. When I select multiple files and then right-click, it doesn't show up. How do I fix that? – akinuri Feb 25 '19 at 08:21

3 Answers3

34

You can use Send To for this. It supports multiple files.

In case this website goes offline:

Open shell:sendto with Windows + R or paste it into your explorer address bar. It should redirect you to:

C:\Users\<yourusername>\AppData\Roaming\Microsoft\Windows\SendTo

Create a shortcut to your program in this folder and you should see it in your explorer right-click menu under Send to

W4ldi
  • 644
  • 5
  • 11
  • 3
    It seems there's a limit to how many files can be sent depending on the files' path. I can send 504 files with paths `C:\test\001.txt`. 504 file names amount to 7560 chars (no space), 8063 chars (space delimited). Sending 505 files (7575 chars [no space]; 8079 [space delimited]) doesn't work. – akinuri Feb 25 '19 at 10:07
  • 1
    Saved me so much time. I use it for compare software.. Thanks – Shakeer Mirza Apr 05 '19 at 10:15
  • 1
    When trying to pass the file `G:\New [folder] (4)\Untitled-2.txt` to a Powershell script, the result becomes `G:\New [folder] 4 \Untitled-2.txt`. It seems that parentheses cannot be parsed correctly. Any solution? – preachers May 27 '19 at 16:12
  • @preachers try escaping parenths with a back tick: `G:\New [folder] \`(4\`)\Untitled-2.txt` – gargoylebident Feb 09 '22 at 23:58
8

You may want to look at this post, as it says that this isn't really possible to pass multiple files to a single instance and you must rely on some form of IPC(Inter process Communication).

Community
  • 1
  • 1
Eternal Learner
  • 2,602
  • 5
  • 27
  • 38
0

Use: Command-Queuer.cmd

I wanted to do the same thing and ended up creating a 'wrapper' .cmd/bat file to queue the commands for me... I use a temporary queue file to: (a) self-nominate a control instance to run the process, and (b) signal to other instances not run the command(s) directly and instead just add their file/parameters to the queue and exit. The script waits X seconds for the other instances to queue their info and then processes the selected files sequentially.

Command-Queuer.cmd
------------------

@ECHO OFF
SETLOCAL

:: SETUP PARAMETERS: Control temp file location and delay before running
SET QueueFile="%TEMP%\Multi-Item-Queue.txt"
SET /A Secs=5

:: MAIN PROGRAM: If the first instance create the queue and wait, otherwise transfer to queue and exit
IF EXIST %QueueFile% ( ECHO %* >> %QueueFile% ) ELSE (
    ECHO %* > %QueueFile%
    ECHO Waiting %Secs% seconds for other files to finish queuing then will activate...
    TIMEOUT /T %Secs% /NOBREAK >nul
    
    REM - ADD YOUR CODE HERE TO PROCESS THE QUEUE FILE AS A WHOLE
    REM - Example: Display popup of all file paths selected: Msg %username% <%QueueFile%
    
    REM - ALTERNATIVELY, ITERATE THROUGH EACH LINE OF THE FILE
    REM - Example: FOR /F "tokens=*" %%Z in (%QueueFile%) DO ( COPY %%Z "C:\Backup" )
    
    :: Delete the queue file when finished
    DEL %QueueFile%
)
GOTO:EOF

NOTE: You will see a empty cmd window appear for a split-second for each file selected, i.e. if you select 30 files then 30 cmd windows will briefly appear, but these can be hidden if desired please check: Run a batch file in a completely hidden way (superuser.com)

Martin
  • 280
  • 1
  • 10