title: Schedule a .vbs file to run in Windows
body: <p>I have a <a href="http://en.wikipedia.org/wiki/VBScript" rel="nofollow noreferrer">VBScript</a> script that starts a cmd prompt, telnets into a device and <a href="http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol" rel="nofollow noreferrer">TFTP</a>'s the configuration to a server. It works when I am logged in and run it manually. I would like to automate it with Windows <a href="http://en.wikipedia.org/wiki/Task_Scheduler" rel="nofollow noreferrer">Task Scheduler</a>.</p>
  
  <p>Any assistance would be appreciated, here is the VBScript script:</p>
  
  <pre><code>set WshShell = WScript.CreateObject("WScript.Shell") 
  WshShell.Run "cmd" 
  WScript.Sleep 100 
  WshShell.AppActivate "C:\Windows\system32\cmd.exe" 
  WScript.Sleep 300 
  WshShell.SendKeys "telnet 10.20.70.254{ENTER}" 
  WScript.Sleep 300 
  WshShell.SendKeys "netscreen" 
  WScript.Sleep 300 
  WshShell.SendKeys "{ENTER}" 
  WScript.Sleep 300
  WshShell.SendKeys "netscreen" 
  WshShell.SendKeys "{ENTER}" 
  WScript.Sleep 300 
  WScript.Sleep 300 
  WshShell.SendKeys "save conf to tftp 10.10.40.139 test.cfg{ENTER}"
  WScript.Sleep 200 
  WshShell.SendKeys "exit{ENTER}" 'close telnet session' 
  set WshShell = WScript.CreateObject("WScript.Shell") 
  WshShell.Run "cmd" 
  WScript.Sleep 100 
  WshShell.AppActivate "C:\Windows\system32\cmd.exe" 
  WScript.Sleep 300 
  WshShell.SendKeys "telnet 10.20.70.254{ENTER}" 
  WScript.Sleep 300 
  WshShell.SendKeys "netscreen" 
  WScript.Sleep 300 
  WshShell.SendKeys "{ENTER}" 
  WScript.Sleep 300
  WshShell.SendKeys "netscreen" 
  WshShell.SendKeys "{ENTER}" 
  WScript.Sleep 300 
  WScript.Sleep 300 
  WshShell.SendKeys "save conf to tftp 10.10.40.139 palsg140.cfg{ENTER}" 'repeat as needed 
  WScript.Sleep 200 
  WshShell.SendKeys "exit{ENTER}" 'close telnet session' 
  WshShell.SendKeys "{ENTER}" 'get command prompt back 
  WScript.Sleep 200 
  WshShell.SendKeys "exit{ENTER}" 'close cmd.exe
  
  WshShell.SendKeys "{ENTER}" 'get command prompt back 
  WScript.Sleep 200 
  WshShell.SendKeys "exit{ENTER}" 'close cmd.exe
  </code></pre>