Vbscript VBS通过cscript中的cmd触发另一个VBS

Vbscript VBS通过cscript中的cmd触发另一个VBS,vbscript,hp-uft,wsh,Vbscript,Hp Uft,Wsh,我有一个VBScript,它可以触发HP ALM中的测试,并与UFT一起运行 -此vbs只能通过使用cscript在cmd中触发来工作 我想知道如何避免先去cmd触发它,而只是创建另一个vbs,用cscript触发文件在cmd中运行。或者你有更好的解决办法 下面的代码不起作用 Set oShell = WScript.CreateObject ("WScript.Shell") oShell.run "cmd.exe" "" c:\Windows\SysWOW64\cscript.exe

我有一个VBScript,它可以触发HP ALM中的测试,并与UFT一起运行 -此vbs只能通过使用
cscript
cmd
中触发来工作

我想知道如何避免先去
cmd
触发它,而只是创建另一个vbs,用
cscript
触发文件在
cmd
中运行。或者你有更好的解决办法

下面的代码不起作用

Set oShell = WScript.CreateObject ("WScript.Shell")

oShell.run "cmd.exe"   "" c:\Windows\SysWOW64\cscript.exe C:\Temp\Unattended.vbs""

Set oShell = Nothing

下面是几个如何运行VBS的示例。如果系统默认运行cscript,则最后一个选项应该有效

Set objShell = CreateObject("WScript.Shell")

'run with wscript
objShell.Run("""C:\Windows\System32\wscript.exe"" ""C:\Test\MyScript.vbs""")

wscript.sleep 5000 'waits 5 seconds before running the next script. This is used for display purposes, not because you have to

'run with cscript
objShell.Run("""C:\Windows\System32\cscript.exe"" ""C:\Test\My Script.vbs""")

wscript.sleep 5000 'waits 5 seconds before running the next script. This is used for display purposes, not because you have to

'run with the default program for vbs files (usually cscript)
objShell.Run("""C:\Test\My Script.vbs""")

请去掉括号。他们在这里不是无效的,但是。另外,默认的解释器是
wscript.exe
,除非您将其更改为
cscript.exe
@AnsgarWiechers really?,它不是一个子解释器。为什么不直接执行
result=objShell.Run(““C:\Windows\System32\cscript.exe”“C:\Test\My Script.vbs”“”)
,然后完成它(只需记住先将结果调暗即可)@Lankymart这将是另一个(可以说是更好的)选择。如果您确实检查返回的退出代码,也就是说。@Ansgarwiecher的问题是因为它不是
子类
,从技术上讲它不是无效的,因为
Run()
方法是
函数
,所以括号很好,不会导致脚本失败。当你像这样调用
Sub
时,困难就在于
mySub(arg1)
(arg1)
不是你想象的那样。@Lankymart不。函数和Sub在这方面是相似的
myFunc(arg1)
mySub(arg1)
都将作为独立语句工作。这不是因为它是传递参数的正确语法,而是因为括号强制按值传递
arg1
myFunc(arg1,arg2)
mySub(arg1,arg2)
都会失败,因为这种语法只有在这样使用时才有效:
ret=myFunc(arg1,arg2)
调用mySub(arg1,arg2)
,否则必须是
myFunc arg1,arg2
mySub arg1,arg2
(无括号)对于SUB和函数。