我有一个在XP机器上运行的预定作业。此作业有时会失败,退出代码不是" 0"。我想编写一个可以在作业后面运行的vbscript并获得" Last Result"。如果结果不正确,那么我希望它给我发一封电子邮件通知我工作失败了。
这可能吗?
答案 0 :(得分:1)
尝试此操作:而不是您的预定作业,安排类似于以下的脚本:
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变量中,您可以收集所有信息到电子邮件...
答案 1 :(得分:0)
for /f "tokens=3 delims=: " %A in ('schtasks /query /tn alarm2 /v /fo list^|findstr /c:"Last Result"') do echo %A
给你最后的结果
这是通过COM
访问TS的方法Set service = CreateObject("Schedule.Service")
call service.Connect("Serenity")
' Get the task folder that contains the tasks.
Dim rootFolder
Set rootFolder = service.GetFolder("\")
Dim taskCollection
Set taskCollection = rootFolder.GetTasks(0)