Em minha missão para erradicar o cmd.exe [sorriso], aqui está um script do Powershell que também deve funcionar para você:
# 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)
}