我有一个 VB 脚本,它通过 BAT 文件从工具触发作业并获得状态错误/成功。 代码是:
intReturn = WShell.Run(strBATFile,0,True)
If intReturn = 1 Then
intReturn = 0
strJobStat = "Complete"
End If
If intReturn = 3 or intReturn=2 Then
intReturn = 1
strJobStat = "Error"
End If
如果作业触发并完成/失败,上面的代码工作正常。但是,如果作业也没有触发(启动),则表示成功。
如果作业没有开始,请建议可以在上面的代码中更改/添加什么。 要处理的错误代码是什么。
提前致谢...
最佳答案
不确定这是否是您要找的。但它包含一个 catch all Else 语句,该语句将捕获 WShell.Run 的返回值不是 1、2 或 3 的任何实例。
如果 bWaitOnReturn 设置为 TRUE - 在您的情况下 - Run 方法返回应用程序返回的任何错误代码。因此,无论 strBATFile 返回什么,WShell.Run 都将返回到 intReturn 中。
intReturn = WShell.Run(strBATFile,0,True)
If intReturn = 1 Then
intReturn = 0
strJobStat = "Complete"
Else If intReturn = 3 or intReturn=2 Then
intReturn = 1
strJobStat = "Error"
Else
strJobStat = "Unexpected Error"
End If
关于vbscript - wshell.run 的返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25734435/