2013-11-05 55 views
0

我已经编写了一个脚本(.wsf)来在特定服务失败时触发电子邮件。对于第一次,第二次和随后的失败,我已经运行了一个程序并在该选项卡中添加了我的.wsf文件。但我没有收到电子邮件警报。我可以知道我应该怎么做才能执行该操作。采取如何在Windows服务恢复中运行Windows脚本文件

步骤:(但没有结果/不工作)

1)在运行程序选项卡,给写一个bat文件和脚本 2)的完整路径inturn调用。 wsf文件 3)在运行程序选项卡时给出管理员cmd.exe路径,并在命令行参数选项卡中给出脚本文件的路径。

注意:我已经在cmd.exe中单独执行了此操作,并且它通过发送电子邮件警报起作用。

为了使服务失败我手动停止它,重新启动它,但没有通知通知。请让我知道我应该进一步从Windows服务恢复选项卡执行脚本。我在此也添加了我的脚本。

<job> 
<script language="VBScript"> 
Option Explicit 
On Error Resume Next 
Dim WshShell 
set WshShell=CreateObject("WScript.Shell") 
WshShell.run "cmd.exe" 
WScript.Sleep 1000 
WshShell.SendKeys "telnet smtp.sample.com 25" 

WshShell.Sendkeys("{Enter}") 
WScript.Sleep 1000 
WshShell.SendKeys "EHLO sample.com" 
WshShell.Sendkeys("{Enter}") 
WScript.Sleep 1000 
WshShell.SendKeys "MAIL FROM:[email protected]" 
WshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
WshShell.SendKeys "RCPT TO:[email protected]" 
WshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
WshShell.SendKeys "DATA" 
WshShell.SendKeys ("{Enter}") 

WScript.Sleep 1000 
WshShell.SendKeys "Subject: Test Email" 
WshShell.SendKeys ("{Enter}") 
WshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
WshShell.SendKeys "Body-Test Email executed by running script" 
WshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
WshShell.SendKeys "." 
WshShell.SendKeys ("{Enter}") 
WScript.Quit 
</script> 
</job> 

回答

0

试图从从系统服务和执行任务的专为桌面使用工具的自动化进程运行在有限的会议,....如果它的工作原理,你有很大的运气。

有很多问题涉及到它的工作,并不确定它是否会在新版本的系统上工作。

如果需要脚本化的telnet会话,您最好的选择将是来自putty包的plink命令行工具。

或者你可以用CDO

Set objEmail = CreateObject("CDO.Message") 
objEmail.From = "[email protected]" 
objEmail.To = "[email protected]" 
objEmail.Subject = "Service is down" 
objEmail.Textbody = "The service has failed" 
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.sample.com" 
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
objEmail.Configuration.Fields.Update 
objEmail.Send 
尝试
相关问题