wordpress   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了windows-server-2003 – Windows任务调度程序电子邮件通知?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我使用 Windows任务计划程序运行可执行文件,成功运行时返回0.但是,如果(1)任务无法运行,或者(2)返回代码(如果不是0),我想要一封电子邮件通知. 这是Windows Server 2003上的Windows任务计划程序可以执行的操作吗? 在我寻求根除cmd.exe [grin]的过程中,这里有一个PowersHell脚本,它也适用于你: # attempt to run your ex
@H_674_14@ 我使用 Windows任务计划程序运行可执行文件,成功运行时返回0.但是,如果(1)任务无法运行,或者(2)返回代码(如果不是0),我想要一封电子邮件通知.

这是Windows Server 2003上的Windows任务计划程序可以执行的操作吗?

在我寻求根除cmd.exe [grin]的过程中,这里有一个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 = "sender@mydomain.com"
    $toaddress = "recipient@mydomain.com"
    $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)
}

大佬总结

以上是大佬教程为你收集整理的windows-server-2003 – Windows任务调度程序电子邮件通知?全部内容,希望文章能够帮你解决windows-server-2003 – Windows任务调度程序电子邮件通知?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。