通过VBScript使用参数执行批处理文件

时间:2013-04-14 16:27:42

标签: vbscript batch-file

场景:要从数据库生成多个报告,我们在命令提示符中执行批处理文件,如

C:\program files> cmdbatchtest1.bat servername date Y Y

使用VBScript我尝试做类似的事情:

set shell=createobject("wscript.shell")
shell.Run "test1.bat.bat", 1, True '''''able to execute batch file alone
shell.Run "cmd /K "& com_e & """\tp.bat""" & "&&" & c & "&&" & d, 1, True '''' unable to execute

请帮我完成这项工作。
提前谢谢。

1 个答案:

答案 0 :(得分:0)

在不起作用的行中,您将&&作为参数传递给批处理脚本。命令解释器可能正在尝试执行cmd /k path\to\tp.bat&&server&&date。尝试将&&改为 Space ,如下所示:

shell.Run "cmd /K "& com_e & """\tp.bat"" " & c & " " & d, 1, True

如果这不能解决问题,我想我们需要了解您的变量com_ecd是如何设置的。


此外,请注意shell.Run存在潜在的安全问题。错误地制作cd的值可能会导致此行执行额外的,可能具有破坏性的命令。请考虑使用Shell.Application对象的Shell.Execute method代替。

set shell=CreateObject("Shell.Application")
' shell.ShellExecute "application", "parameters", "path", "verb", window
shell.ShellExecute "tp.bat", c & " " & d, com_e, "runas", 1
set shell=nothing 

有关详细信息,请参阅this question的答案。

相关问题