【问题标题】:How to add new items to right-click event on Folders and Files in Windows?如何在 Windows 中的文件夹和文件的右键单击事件中添加新项目?
【发布时间】:2009-11-30 18:50:56
【问题描述】:

我在谷歌上做了几个谷歌教程。

我可以通过这样做将右键菜单项添加到 FOLDER

[HKEY_CLASSES_ROOT\Directory\shell\Command]
@="TestRightClick:"

[HKEY_CLASSES_ROOT\Directory\shell\Command\Command]
@="myExecutable.exe %L"

我也需要将其添加到文件中。

1) 我在注册表中的哪个位置添加它?

2) 如果我选择多个文件,如何将参数传递给我的可执行文件?

相关:

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

【问题讨论】:

    标签: windows events registry


    【解决方案1】:

    你可以用我的程序singleinstance来做到这一点。 不涉及外壳扩展。

    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\SystemFileAssociations\.txt\Shell\p4merge]
    "MultiSelectModel"="Player"
    
    [HKEY_CLASSES_ROOT\SystemFileAssociations\.txt\Shell\p4merge\Command]
    @="\"d:\\singleinstance.exe\" %1 \"C:\\Program Files\\Perforce\\p4merge.exe\" $files --si-timeout 400"
    

    【讨论】:

    • 我尝试了您的解决方案.. 在使用您定义的值创建 command 后,我下载了 singleinstance.exe。但我收到了Windows cannot access the specified device, path, or file. You may not have the appropriate permission to access the item. 这个错误。
    【解决方案2】:

    您要查找的关键字是“动词”或“处理程序”而不是“事件”。

    可以将特定文件扩展名的上下文菜单动词放在文件类型的 ProgID、Perceived Type 键(如果文件类型具有可感知的类型)、AllFileSystemObjects 键或基类键 (*) 下。

    请注意,写入 HKEY_CLASSES_ROOT 配置单元中的这些键会将写入重定向到 HKEY_LOCAL_MACHINE\Software\Classes,并且需要提升权限。如果您写入HKEY_CURRENT_USER\Software\Classes 树,您可以使用标准用户权限执行此操作。

    选择多个文件的情况由您决定。您选择的每个文件都会启动一个应用程序实例。您可以通过检查应用程序的另一个实例是否正在运行并使用进程间通信通知现有实例已选择其他扩展来解决此问题。

    在 MSDN 上,请务必阅读

    【讨论】:

    • 这也是一个很好的答案,但不够具体。谢谢。
    【解决方案3】:
    1. 文件具有扩展名的上下文菜单。将您的 Command 注册表项添加到适当的扩展名或 HKEY_CLASSES_ROOT\* 以影响所有文件。
    2. 您可以使用 %1 将文件名传递给应用程序(就像您在上面使用 %L 指示的那样)。如果您选择多个文件,每个文件都将被单独调用,就像您分别右键单击每个文件一样。

    我不知道有什么简单的方法可以将多个项目从右键单击上下文菜单传递到一个可执行实例。

    【讨论】:

    • @2.关于如何避免多次调用我的应用程序并仍然传递多个文件路径的任何建议。也许用线程?
    • 此解决方案的更多详细信息:我向 HKEY_CLASSES_ROOT*\Shell\TestRightClick 添加了一个键,然后我添加了命令键 HKEY_CLASSES_ROOT*\Shell\TestRightClick\Command ,然后将我的可执行文件传递给默认字符串
    【解决方案4】:

    请参阅 GitHub SingleInstanceAccumulator,了解 C# 实现的陈旧的 Mutex + COPYDATA 方法。

    other stack-o's表达需求。

    资源管理器上下文菜单配置

    ::creates the entry
    :: and crucial multi-file handling property
    reg add "HKEY_CLASSES_ROOT\FileType\shell\YourNewContextMenu" /f /v "MultiSelectModel" /d "Player"
    
    ::your desired command line
    reg add "HKEY_CLASSES_ROOT\FileType\shell\YourNewContextMenu\command" /f /ve /t REG_EXPAND_SZ /d "***see command line examples***"
    

    例如在我的系统上,对于“.mov”文件,我会将上面的 FileType 替换为 VLC.mov

    复杂的 REG ADD 示例

    将上面的“* see command line examples *”替换为您想要的命令行。
    注意:quotes & environment variables 必须被转义,并且对于初始命令和字符串后面的命令,转义工作略有不同!?!

    λ reg add "HKEY_CLASSES_ROOT\VLC.mov\shell\Transcode\command" /f /ve /t REG_EXPAND_SZ /d "\"^%bin^%\SingleInstanceAccumulator\" -f \"-c:powershell -ExecutionPolicy bypass "\"^%bin^%\test.ps1\"" -list '$files'\" \"%1\""
    

    SingleInstanceAccumulator.exe 用法

    "-c:command line" (default: cmd /c echo $files && pause)
      $files will be replace with aggregated list
    
    -f = output each item on separate line to new tempfile
      $files will be replaced by the tempfile path
      quote will default to nothing
    
    -d:delimiter (default: ,)
    -q:quote (default: ")
    -t:timeout millisecs (default: 200)
    -w = hidden launch
    -v = debug output
    

    命令行示例

    注意:初始命令必须有路径,shell > 命令才能工作

    PowerShell 和临时文件

    注意:-f用法

    "%bin%\SingleInstanceAccumulator" -f "-c:powershell -ExecutionPolicy bypass "%bin%\test.ps1" -list '$files'" "%1"
    

    PowerShell & 内联 文件列表

    注意:-q用法

    "%bin%\SingleInstanceAccumulator" -q:' "-c:powershell -ExecutionPolicy bypass "%bin%\test.ps1" -list $files" "%1"
    

    test.ps1(带有临时文件)

    powershell
    param(
      [String]$listFilePath
    )
    
    gc $listFilePath | % { $_ }
    
    pause
    
    erase $listFilePath
    
    pause
    

    test.ps1(带有文件数组参数)

    param(
      [String[]]$filesList
    )
    
    $filesList | % { $_ }
    
    pause
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-10
      • 1970-01-01
      • 2014-01-11
      • 1970-01-01
      • 2021-11-29
      • 1970-01-01
      相关资源
      最近更新 更多