Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

VBS script does not run when logged off

$
0
0

Hi Guys,

I have scheduled a batch file to run at 3am every morning on my windows 2003 server. When I am logged on, the batch file executes perfectly, but when I am logged off it does not. The following is the contents of this batch file.  Essentially the first vbs is suppose to send commands to a devise causing it to restart. The batch file will then wait 180 for the devise to restart and then execute some more commands, the output of which will be redirected to a log file. This log file will then be emailed to me. I know the batch file executes because I get an email with the attached log file. But the log file is not capturing the output and the devise does not restart. 

Would be grateful for some feedback on this issue, thanks   

The batch file:

cscript Restarts_Smartnets.vbs
TIMEOUT /T 180 >nul
cscript Displays_Uptime.vbs
cscript Emails_Uptime.vbs 

    

Restart_Smartnets script:

Option Explicit
Dim objShell
Set objShell = CreateObject("WScript.Shell")

  objShell.Run "telnet X.X.X.X"
  RestartDevice

Sub RestartDevice
  Wscript.Sleep 400
  objShell.SendKeys "username"
  objShell.SendKeys "{ENTER}" 
  WScript.Sleep 300 
  objShell.SendKeys "password"
  objShell.SendKeys "{ENTER}" 
  WScript.Sleep 400
  objShell.SendKeys "hub.restart"
  objShell.SendKeys "{ENTER}"
  WScript.Sleep 400 
  objShell.Run "taskkill /F /IM telnet.exe"
  WScript.Sleep 400
End Sub
WScript.Quit

The Get_UPtime script

Option Explicit
Dim objShell 

Set objShell = CreateObject("WScript.Shell")

  objShell.Run "telnet X.X.X.X -f Chan1.txt"
  GetUptime

Sub GetUptime
  Wscript.Sleep 400
  objShell.SendKeys "username"
  objShell.SendKeys "{ENTER}" 
  WScript.Sleep 300 
  objShell.SendKeys "password"
  objShell.SendKeys "{ENTER}" 
  WScript.Sleep 400
  objShell.SendKeys "hub.uptime"
  objShell.SendKeys "{ENTER}"
  WScript.Sleep 400 
  objShell.SendKeys "exit"
  objShell.SendKeys "{ENTER}"
  WScript.Sleep 400
  objShell.Run "taskkill /F /IM telnet.exe"
  WScript.Sleep 400
End Sub
WScript.Quit 

Email Script:

Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "Smartnet uptime logs" 
objMessage.From = "" 
objMessage.To = ""
objMessage.Cc = ""
objMessage.HTMLBody = "</h2>Please see attached Logs.</h2>" 
objMessage.AddAttachment "E:\DO NOT RUN SCRIPTS\Chan1.txt"
objMessage.Send







Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>