【问题标题】:How to call Run() with parameters如何使用参数调用 Run()
【发布时间】:2013-02-22 02:53:45
【问题描述】:

我在 Windows Batch 中有这行代码

start "" /wait /i "C:\Program Files\Sandboxie\Start.exe" /box:NetBeans /wait "C:\Program Files\NetBeans 7.3\bin\netbeans64.exe"

我想通过 VBScript 运行它。但我不知道如何在内部有空格的参数中传递路径。

我想出了这样的东西:

Set objShell = CreateObject("Wscript.Shell")
objShell.Run("C:\Program Files\Sandboxie\Start.exe" /box:NetBeans /wait "C:\Program Files\NetBeans 7.3\bin\netbeans64.exe"), 1, True

但是有一个错误:

预期:')'

【问题讨论】:

  • 检查堆栈溢出,他们可能知道。还有一种方法可以在 exe 运行后调用来复制 ini 文件。 VB很整洁。

标签: batch-file parameters vbscript


【解决方案1】:

在文字字符串中,单个双引号字符由两个双引号字符表示。因此,请尝试以下方法:

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run """C:\Program Files\Sandboxie\Start.exe"" /box:NetBeans /wait ""C:\Program Files\NetBeans 7.3\bin\netbeans64.exe""", 1, True
Set objShell = Nothing

【讨论】:

    【解决方案2】:

    我喜欢使用以下系统来嵌入引号:

    strCommand = Quotes("C:\Program Files\Sandboxie\Start.exe") & _
             " /box:NetBeans /wait " &                            _
             Quotes("C:\Program Files\NetBeans 7.3\bin\netbeans64.exe")
    
    Function Quotes(ByVal strValue)
        Quotes = Chr(34) & strValue & Chr(34)
    End Function
    

    它更容易阅读。

    【讨论】:

      猜你喜欢
      • 2017-08-24
      • 2021-10-16
      • 2021-12-28
      • 2019-09-30
      • 2020-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多