2012-12-03 85 views
1

我有一個vbscript,運行在我的服務器上,每當文件被添加到某個目錄時,通過telnet發送一封電子郵件。該腳本連續運行,但是如果我沒有通過RemoteDesktop登錄,它將不會執行telnet命令。我可以在沒有登錄的情況下在服務器上運行無人值守的vb腳本嗎?

任何人都可以提出一種方法來讓我執行腳本時,我沒有登錄?

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 

回答

相關問題