玖色琉璃-轮回 2019-08-15 17:25 采纳率: 0%
浏览 424
已结题

VB 怎么在多选文件后,右键菜单打开程序为只运行一个EXE?

我自己写了注册表,让鼠标右键点击一个文件时,增加了一项“我的应用”到ContextMenu。
现在我的问题是,我选中一个文件,这样右键操作,则运行“我的应用“一次。
但是,如果我多选文件,再这样右键操作,则会运行”我的应用“N次。
我想问,有没有办法能在我多选的时候,让”我的应用“只运行一次且获得我多选的所有文件的命令行参数(这个文件的绝对路径)。求VB解决方案,最好有代码实例,万分感谢!
我自己已经查了很多,比如shell拓展,进程间通信,但是可能是我悟性不够,没太懂。
上面表述也许不够清楚,具体想实现的例子就是像 压缩软件 在多选文件压缩的时候的那个”添加到压缩文件“的效果。
图片说明

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-08-16 00:11
    关注

    stackoverflow上有人给出一个办法

    编写一个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) '这里是你实际要调用的用来打开文件的VB程序。用Command语句和Split得到文件
    else 'This is not the first instance. Before exiting, sleep for a moment for the first one to detect.
        WScript.Sleep 4000
    end if
    

    注册表中 wscript //nologo "Full Path\myscript.vbs" "%1" 作为命令行(Full Path\myscript.vbs是这个脚本的路径)

    具体看 https://stackoverflow.com/questions/32107534/more-about-opening-multiple-files-through-the-context-menu

    这里还有一个基于消息通讯的
    https://stackoverflow.com/questions/21062046/open-multiple-files-via-shell-context-menu-as-params
    不过是delphi写的,思路我看了下,VB应该也可以实现。

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作