计划在Windows中运行.vbs文件 [英] Schedule a .vbs file to run in Windows
问题描述
我有一个 VBScript 脚本启动cmd提示,telnets到设备和< a href =http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol =nofollow noreferrer> TFTP 将配置发送到服务器。它工作,当我登录并手动运行它。我想使用Windows 任务计划程序自动化。
I have a VBScript script that starts a cmd prompt, telnets into a device and TFTP'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 Task Scheduler.
任何帮助都将不胜感激,这里是VBScript脚本:
Any assistance would be appreciated, here is the VBScript script:
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
推荐答案
任务,使用您的凭据运行脚本。提醒自己,每次更改密码时,都需要更新任务上的凭据。这是一个好主意,通过电子邮件或某事每次它的运行脚本电话回家,以便你可以知道是否正在执行。
Add a scheduled task that runs the script with your credentials. Remind yourself that you need to update the credentials on the task every time you change your password. It be a good idea to have the script "phone home" via email or something every time it is run so that you can tell if it is being executed.
它可能也是一个好主意,为这些类型的活动设置一个单独的服务id。您可能不需要频繁更改服务ID上的密码。
It might also be a good idea to set up a separate service id for these sorts of activities. You may not need to change the password on the service id as frequently.
这篇关于计划在Windows中运行.vbs文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!