vbscript - wshell.run 的返回值

标签 vbscript

我有一个 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/

相关文章:

vbscript - 通过 VBA 以编程方式配置 Office 2010 Word 功能区

vbscript - 经典 ASP : replacing a string

c# - 经典 ASP 是否有与 C# 中的 #if DEBUG 语句等效的语句?

shell - Ping 和启动程序

javascript - 如何使用ajax调用在浏览器上加载html响应

security - 如何使用 WScript.Shell 对象调试 ASP 权限问题?

windows - 使用 Windows shell 脚本自动打开文件

.net - vbscript 检查是否安装了.net 2.0

sql - 如何使用vbscript捕获SQL错误

vbscript - 如何使用vbscript对数组进行排序?