0

Scenario: To generate multiple reports from the database, we execute the batch file in command prompt like

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

With VBScript I tried to do similar:

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

Please help me to get this working.
Thanks in advance.

4

1 回答 1

0

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

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

如果这不能解决它,我想我们需要看看你的 variables和com_e是如何设置的。cd


另外,请注意shell.Run存在潜在的安全问题。cd可能导致该行执行额外的、具有潜在破坏性的命令的邪恶制作值。考虑改用Shell.Application对象的Shell.Execute 方法

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 

有关更多信息,请参阅此问题的答案。

于 2013-04-14T18:34:56.663 回答