我可以使用VBScript返回预定作业窗口的最后结果如何呢? [英] Can I use vbscript to return the last result of a windows scheduled job?
本文介绍了我可以使用VBScript返回预定作业窗口的最后结果如何呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个XP的机器上运行的计划作业。不时这个作业失败比0退出code。我想写在作业后面跑,并得到了最后结果一个VBScript。如果这一结果是不正确的话,我希望它踢电子邮件给我,通知我说,作业失败。
I have a scheduled job that runs on an XP machine. From time to time this job fails with an exit code other than "0". I want to write a vbscript that can run behind the job and get the "Last Result". If that result is not correct then I want it to kick of an email to me notifying me that the job failed.
这是可能的吗?
推荐答案
试试这个:不是你的计划作业,安排一个脚本类似于:
Try this: instead of your scheduled job, schedule a script similar to:
VB Script Document
option explicit
'On Error Resume Next
On Error GoTo 0
Dim strResult: strResult = Wscript.ScriptName & vbNewLine
Dim WshShell, oExec, appExitCode, appExitString
Set WshShell = CreateObject("WScript.Shell")
ShowResult( "%comspec% /C dir *.*")
ShowResult( "%comspec% /C dir*.*")
ShowResult( "YourSchedApp")
Wscript.Echo strResult
Wscript.Quit
Private Sub ShowResult( ByVal AppToRun)
strResult = strResult & vbNewLine & AppToRun & vbNewLine
On Error Resume Next
Set oExec = WshShell.Exec( AppToRun)
appExitCode = Err.Number
If appExitCode = 0 Then
Do While oExec.Status = 0
WScript.Sleep 100
Loop
appExitCode = oExec.ExitCode
appExitString = ""
Else
appExitString = "Error 0x" & Hex( appExitCode) & vbTab & Err.Description
Err.Clear
End If
On Error GoTo 0
strResult = strResult & "Exit code " & CStr( appExitCode) & vbNewLine & appExitString
Set oExec = Nothing
End Sub
在strResult变量,你可以收集所有信息以电子邮件...
in strResult variable you can collect all info to e-mail...
这篇关于我可以使用VBScript返回预定作业窗口的最后结果如何呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文