如何将多个文件名传递给上下文菜单 Shell 命令?

问题描述 投票:0回答:3

将单个文件名传递给上下文菜单 shell 命令很简单:

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

但是如果我选择多个文件,

program.exe
被调用为each 这样的选定文件。

我想做的是只调用一次

program.exe
,将当前选择的所有文件名传递给它。

如何做到这一点?

windows shell registry contextmenu windows-shell-extension-menu
3个回答
34
投票

您可以为此使用发送至。它支持多个文件。

万一本网站下线:

使用

shell:sendto
打开
Windows + R
或将其粘贴到资源管理器地址栏中。它应该将您重定向到:

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

在此文件夹中创建程序的快捷方式,您应该在资源管理器右键单击菜单中看到它

Send to


8
投票

您可能想看看这篇文章,因为它说将多个文件传递给单个实例是不可能的,您必须依赖某种形式的 IPC(进程间通信)。


0
投票

使用:Command-Queuer.cmd

我想做同样的事情并最终创建了一个“包装器”.cmd/bat 文件来为我排队命令......我使用一个临时队列文件来:(a)自我提名一个控制实例来运行进程,以及 (b) 向其他实例发出信号,不要直接运行命令,而只是将它们的文件/参数添加到队列中并退出。该脚本等待 X 秒,让其他实例对它们的信息进行排队,然后按顺序处理所选文件。

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

注意:对于每个选定的文件,您将看到一个空的 cmd 窗口出现一瞬间,即如果您选择 30 个文件,则将短暂显示 30 个 cmd 窗口,但如果需要,可以隐藏这些窗口,请检查:运行批处理文件以完全隐藏的方式(superuser.com)

© www.soinside.com 2019 - 2024. All rights reserved.