Service 如何在Windows服务恢复中运行Windows脚本文件

Service 如何在Windows服务恢复中运行Windows脚本文件,service,recovery,windows-scripting,wsh,Service,Recovery,Windows Scripting,Wsh,我编写了一个脚本(.wsf),在特定服务失败时触发电子邮件。对于第一次、第二次和后续的失败,我给了run一个程序,并在该选项卡中添加了我的.wsf文件。但我没有收到电子邮件提醒。我可以知道我应该怎么做来执行吗 采取的步骤:(但无结果/不起作用) 1) 在“运行程序”选项卡中,提供了脚本的完整路径 2) 编写了一个bat文件,哪个inturn称之为.wsf文件 3) 在“运行程序”选项卡中提供了administrator cmd.exe path的路径,并在“命令行参数”选项卡中提供了脚本文件的路

我编写了一个脚本(.wsf),在特定服务失败时触发电子邮件。对于第一次、第二次和后续的失败,我给了run一个程序,并在该选项卡中添加了我的.wsf文件。但我没有收到电子邮件提醒。我可以知道我应该怎么做来执行吗

采取的步骤:(但无结果/不起作用)

1) 在“运行程序”选项卡中,提供了脚本的完整路径 2) 编写了一个bat文件,哪个inturn称之为.wsf文件 3) 在“运行程序”选项卡中提供了administrator cmd.exe path的路径,并在“命令行参数”选项卡中提供了脚本文件的路径

注意:我已经在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:alice@sample.com"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys "RCPT TO:bob@sample.com"
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>

选项显式
出错时继续下一步
昏暗的地狱
设置WshShell=CreateObject(“WScript.Shell”)
WshShell.run“cmd.exe”
WScript.Sleep 1000
WshShell.SendKeys“telnet smtp.sample.com 25”
Sendkeys(“{Enter}”)
WScript.Sleep 1000
WshShell.SendKeys“EHLO sample.com”
Sendkeys(“{Enter}”)
WScript.Sleep 1000
WshShell.SendKeys“邮件发件人:alice@sample.com"
WshShell.SendKeys(“{Enter}”)
WScript.Sleep 1000
WshShell.SendKeys“RCPT至:bob@sample.com"
WshShell.SendKeys(“{Enter}”)
WScript.Sleep 1000
WshShell.SendKeys“数据”
WshShell.SendKeys(“{Enter}”)
WScript.Sleep 1000
WshShell.SendKeys“主题:测试电子邮件”
WshShell.SendKeys(“{Enter}”)
WshShell.SendKeys(“{Enter}”)
WScript.Sleep 1000
WshShell.SendKeys“通过运行脚本执行正文测试电子邮件”
WshShell.SendKeys(“{Enter}”)
WScript.Sleep 1000
WshShell.SendKeys“
WshShell.SendKeys(“{Enter}”)
WScript.Quit

尝试使用专为桌面使用而设计的工具,从系统服务执行的、在有限会话中运行的任务中自动化流程。。。。如果成功的话,你会很幸运的

要让它工作起来有很多问题,而且不确定它是否能在新版本的系统上工作

如果需要脚本化的telnet会话,更好的选择是putty包中的plink命令行工具

或者你可以试试CDO

Set objEmail = CreateObject("CDO.Message")
objEmail.From = "alice@sample.com"
objEmail.To = "bob@sample.com"
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