我有一个可执行文件,我想从带有参数的CMD运行。
我试过
Set oShell = WScript.CreateObject("WScript.Shell")
oShell.Run "cmd strExePath Mode strPath strBase strResponse strLogPath"
当我运行此脚本时,它只会打开CMD。传递参数的正确方法是什么?
答案 0 :(得分:0)
对于running来自VBScript的可执行文件,您不应该需要CMD。这样的事情就足够了:
oShell.Run "exepath arg1 arg2 ...", 0, True
如果由于某种原因必须使用CMD,请确保使用其中一个参数/c
(执行后关闭CMD)或/k
(执行后保持CMD打开)。
oShell.Run "%COMSPEC% /c exepath arg1 arg2 ...", 0, True
请注意,无论哪种方式,VBScript只会扩展命令字符串中的环境变量(例如%COMSPEC%
),而不是VBScript变量。如果要使用VBScript变量构造命令字符串,则需要使用字符串连接:
exepath = "C:\path\to\your.exe"
oShell.Run """" & exepath & """ arg1 arg2 ...", 0, True
额外的双引号用于处理exepath
中的潜在空格。