加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows-server-2003 – Windows任务调度程序电子邮件通知?

发布时间:2020-12-13 23:37:17 所属栏目:Windows 来源:网络整理
导读:我使用 Windows任务计划程序运行可执行文件,成功运行时返回0.但是,如果(1)任务无法运行,或者(2)返回代码(如果不是0),我想要一封电子邮件通知. 这是Windows Server 2003上的Windows任务计划程序可以执行的操作吗? 在我寻求根除cmd.exe [grin]的过程中,这里有
我使用 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_exemyprog.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)
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读