1

我有一个在我的服务器上运行的 vbscript,并在将文件添加到某个目录时通过 telnet 发送电子邮件。该脚本持续运行,但是如果我没有通过 RemoteDesktop 登录,它将不会执行 telnet 命令。

任何人都可以建议一种在我未登录时执行此脚本的方法吗?

Option Explicit 
Dim fso, count, src, folder, file, ncount, cloner 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set cloner = CreateObject("WScript.Shell")
src = "F:/serverfolders/public/camera" 
Set folder = fso.GetFolder(src) 
count = 0 
For Each file In folder.files 
  If LCase(fso.GetExtensionName(file)) = "mp4" Then 
  count = count + 1 
End If 
Next
ncount = count
WScript.Echo "Initial Count: " & count 

Do 

count = 0 
For Each file In folder.files 
  If LCase(fso.GetExtensionName(file)) = "mp4" Then 
  count = count + 1 
  End If
  If LCase(fso.GetExtensionName(file)) = "x" Then Exit DO
Next
if count > ncount then 
  Call Alarm()
  ncount = count
End If
WScript.Sleep 10000
Loop

Sub Alarm
cloner.run"cmd",1,false
WScript.Sleep 1000

cloner.SendKeys"telnet smtp.1and1.com 587"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000

cloner.AppActivate "telnet smtp.1and1.com"
WScript.Sleep 1000

cloner.SendKeys"EHLO ****.com"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000

cloner.SendKeys"auth login"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000

cloner.SendKeys"password"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000

cloner.SendKeys"password2"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000

cloner.SendKeys"MAIL FROM: ****.com"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000

cloner.SendKeys"RCPT TO: ****.com"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000

cloner.SendKeys"DATA"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000

cloner.SendKeys"Subject:Motion Alarm Detected"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000
cloner.SendKeys("{Enter}")
WScript.Sleep 1000

cloner.SendKeys"Motion Alarm Detected"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000

cloner.SendKeys"."
cloner.SendKeys("{Enter}")
WScript.Sleep 2000

cloner.SendKeys"quit"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000

cloner.SendKeys("{Enter}")
WScript.Sleep 10000

End Sub
4

1 回答 1

0

您可以通过以下两种方式之一执行此操作: 1)使用命令行程序SC.EXE创建新的 Windows 服务。该服务将配置为运行您的脚本,并且需要使用特定帐户(新帐户或现有帐户)。您将使用 script.vbs 作为可执行文件。

2)计划任务

于 2012-12-05T07:07:13.240 回答