【问题标题】:How to run Windows Script File in Windows service recovery如何在 Windows 服务恢复中运行 Windows 脚本文件
【发布时间】:2013-11-15 23:06:35
【问题描述】:

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

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

1) 在运行程序选项卡中,给出了脚本的完整路径 2)编写一个bat文件,然后调用该.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: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>

【问题讨论】:

    标签: service recovery windows-scripting wsh


    【解决方案1】:

    尝试使用专为桌面使用而设计的工具从系统服务执行的任务中自动化流程,该任务在有限的会话中运行,....

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

    如果需要脚本化的 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-02
      • 1970-01-01
      • 1970-01-01
      • 2010-09-07
      • 2014-12-17
      相关资源
      最近更新 更多