【问题标题】:More about Opening Multiple Files through the Context Menu有关通过上下文菜单打开多个文件的更多信息
【发布时间】:2019-10-06 02:55:36
【问题描述】:

StackOverflow 线程之前已经处理过这个主题,但总是在编写代码的上下文中。我只是想编辑注册表。

我正在尝试在 MP4 文件类型上创建上下文菜单项。有时我需要将声音剥离到 MP3 中,用 Audacity 进行编辑,然后将其放回 MP4。为此,我使用 DVDVideoSoft 的 FreeVideoToMP3Converter.exe。这个应用程序可以一次转换多个 MP4。我可以将它们拖放到它的窗口上并让它全部打开;执行具有多个文件名的命令行对所有文件都使用一个实例;并使用 SendTo 在单个实例中打开多个文件。我似乎不能做的是编辑 MP4 文件类型的上下文菜单,以便我可以选择多个 MP4 文件并在单个实例中打开它们。 StackOverflow 和网络上的研究表明了三种方法:

  1. 在动词上使用 MultiSelectModel=Player
  2. 使用 DDE
  3. 编写 contextMenuHandler 代码

3 不适用,并且 1 没有产生所需的行为。对于 2,我猜诀窍是弄清楚应用程序名称是什么。这是我目前拥有的(在 Windows 10 中):

Windows Registry Editor Version 5.00

[HKEY_USERS\S-1-5-21-3229476284-161306217-3300585696-1001\SOFTWARE\Classes\AppX6eg8h5sxqq90pv53845wmnbewywdqq5h\Shell\ConverttoMP3]
@="Convert to MP3"
"MultiSelectModel"="Player"

[HKEY_USERS\S-1-5-21-3229476284-161306217-3300585696-1001\SOFTWARE\Classes\AppX6eg8h5sxqq90pv53845wmnbewywdqq5h\Shell\ConverttoMP3\command]
@="\"C:\\Program Files (x86)\\DVDVideoSoft\\Free Video to MP3 Converter\\FreeVideoToMP3Converter.exe\" \"%1\""

[HKEY_USERS\S-1-5-21-3229476284-161306217-3300585696-1001\SOFTWARE\Classes\AppX6eg8h5sxqq90pv53845wmnbewywdqq5h\Shell\ConverttoMP3\ddeexec]
@="Open(\"%1\")"

[HKEY_USERS\S-1-5-21-3229476284-161306217-3300585696-1001\SOFTWARE\Classes\AppX6eg8h5sxqq90pv53845wmnbewywdqq5h\Shell\ConverttoMP3\ddeexec\application]
@="FreeVideoToMP3Converter"

[HKEY_USERS\S-1-5-21-3229476284-161306217-3300585696-1001\SOFTWARE\Classes\AppX6eg8h5sxqq90pv53845wmnbewywdqq5h\Shell\ConverttoMP3\ddeexec\topic]
@="system"

在两个选定的 MP4 上使用上下文菜单会导致应用打开其中一个,另一个消息框显示“将命令发送到程序时出现问题”。首先猜测是因为我没有得到正确的 DDE 应用程序名称。

当然,我可以使用 SendTo 并获得所需的结果(并且在我等待响应时会这样做),但我也想在上下文菜单中得到它。所以我的问题是双重的,具体的和一般的。首先,如何确定 DDE 将用作应用程序名称,以便正确指定它?例如,Textpad 的 DDE 应用程序名称是“Textpad.7”,这是一个在注册表中没有其他地方出现的字符串。怎么会知道呢?一篇文章说它通常是带有“.exe”的文件名,但这就是我上面所说的,不,这次不是。其次,如果我走错了路,需要换个方向,请指路。

以前有关此主题的 StackOverflow 线程说过“它不会像你希望的那样容易”,但我不禁注意到 SendTo 做到了,甚至没有“%1”。那么 SendTo 知道我不知道什么?

【问题讨论】:

    标签: registry contextmenu dde


    【解决方案1】:

    在 Windows XP 上制作:

    也可以在更高版本的 Windows 上运行。

    Windows 为每个选定的文件执行一次上下文菜单项命令。 我通过编写一个 .vbs 脚本来连接其所有实例的参数,然后只调用一次应用程序,将所有文件路径作为参数来解决这个问题。

    myscript.vbs:

    set WshShell = WScript.CreateObject("WScript.Shell")
    set WMIService = GetObject("winmgmts:root\cimv2")
    
    dim FirstCommandLine, CommandLineParts, AllFiles
    
    set AllInstances1 = WMIService.ExecQuery("Select CommandLine FROM Win32_Process WHERE CommandLine LIKE '%" & wscript.scriptname & "%'")
    For Each item In AllInstances1
        FirstCommandLine = item.CommandLine 'Get the command line of the first instance of this script
        exit for
    Next
    
    if InStr(FirstCommandLine,WScript.Arguments.Unnamed(0)) then 'This is the first instance
        WScript.Sleep 400
        'Update instance list to check if other instances appeared
        set AllInstances2 = WMIService.ExecQuery("Select CommandLine FROM Win32_Process WHERE CommandLine LIKE '%" & wscript.scriptname & "%'")
        while AllInstances2.count > AllInstances1.count 'While other instances keep appearing
            WScript.Sleep 400
            'Keep updating instance list
            set AllInstances1 = AllInstances2
            set AllInstances2 = WMIService.ExecQuery("Select CommandLine FROM Win32_Process WHERE CommandLine LIKE '%" & wscript.scriptname & "%'")
        wend
        For Each item In AllInstances2
            CommandLineParts = Split(item.CommandLine,"""")
            AllFiles = AllFiles & """" & CommandLineParts(UBound(CommandLineParts)-1) & """ " 'Get all the file paths
        Next
        WshShell.Run("""Path\to your\application.exe"" /switches" & AllFiles)
    else 'This is not the first instance. Before exiting, sleep for a moment for the first one to detect.
        WScript.Sleep 4000
    end if
    

    要使用它,您需要在 HKEY_CLASSES_ROOT 中创建一个适当的注册表项,使用以下命令:

    wscript //nologo "Full Path\myscript.vbs" "%1"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      相关资源
      最近更新 更多