Windows任务调度程序电子邮件通知?

我正在使用Windows任务计划程序来运行成功运行时返回0的可执行文件。 但是,如果(1)任务运行失败,或者(2)返回码不是0,我想要发送电子邮件通知。

这是Windows Server 2003上的Windows任务计划程序可以做的吗?

在我的追求cmd.exe [笑],这是一个Powershell脚本,也应该为你工作:

# attempt to run your exe. iex is an alias for the invoke-expression cmd iex c:\path_to_exe\myprog.exe # $? lets us know if the previous command was successful or not # $LASTEXITCODE gives us the exit code of the last Win32 exe execution if (!$? -OR $LASTEXITCODE -gt 0) { $smtpServer = "smtp.mydomain.com" $fromAddress = "[email protected]" $toAddress = "[email protected]" $subject = "FAIL" $msgBody = "HEY, YOU GOT PROBLEMS" # This block is optional depending on your SMTP server config # You need it if your SMTP server requires authentication $senderCreds = new-object System.Net.networkCredential $senderCreds.UserName = "senderusername" $senderCreds.Password = "senderpwd" $smtpClient = new-object Net.Mail.SmtpClient($smtpServer) $smtpClient.Credentials = $senderCreds $smtpClient.Send($fromAddress,$toAddress,$subject,$msgBody) } 

一个非常简单的技巧就是将命令封装在CMD /批处理脚本中,并使用返回的错误级别和Blat有条件地发送电子邮件。