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脚本,它启动cmd提示符,telnet到设备,TFTP是服务器的配置。它在我登录并手动运行时有效。我想用Windows Task Scheduler自动化它。
Any assistance would be appreciated, here is the VBScript script:
任何帮助将不胜感激,这是VBScript脚本:
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
6 个解决方案
#1
4
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.
添加使用您的凭据运行脚本的计划任务。提醒您自己每次更改密码时都需要更新任务的凭据。每次运行时通过电子邮件或其他东西使脚本“手机回家”是一个好主意,以便您可以判断它是否正在执行。
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.
为这些类型的活动设置单独的服务ID也是一个好主意。您可能不需要经常更改服务ID上的密码。
#2
3
You can add a scheduled task and enter no credentials or password for it. This will cause it to run under LOCAL SYSTEM (which normally is the context the Task Scheduler service uses).
您可以添加计划任务,也不输入任何凭据或密码。这将导致它在LOCAL SYSTEM(通常是Task Scheduler服务使用的上下文)下运行。
Be aware that this is a backdoor vulnerability scenario: Anyone allowed to edit your script file could misuse it to do undesirable things on the machine that runs the task. Put proper permission on the script file to prevent that. On the other hand - a task running as LOCAL SYSTEM cannot wreck havoc over the network.
请注意,这是一个后门漏洞场景:任何允许编辑脚本文件的人都可能会滥用它来在运行任务的计算机上执行不需要的操作。在脚本文件上放置适当的权限以防止这种情况。另一方面 - 作为LOCAL SYSTEM运行的任务不能破坏网络上的破坏。
I propose you condense your script file a little:
我建议你稍微压缩你的脚本文件:
Set WshShell = WScript.CreateObject("WScript.Shell") Run "cmd.exe" SendKeys "telnet 10.20.70.254{ENTER}" SendKeys "netscreen" SendKeys "{ENTER}" SendKeys "netscreen" SendKeys "{ENTER}" SendKeys "save conf to tftp 10.10.40.139 test.cfg{ENTER}" SendKeys "exit{ENTER}" 'close telnet session' Run "cmd.exe" SendKeys "telnet 10.20.70.254{ENTER}" SendKeys "netscreen" SendKeys "{ENTER}" SendKeys "netscreen" SendKeys "{ENTER}" SendKeys "save conf to tftp 10.10.40.139 palsg140.cfg{ENTER}" 'repeat as needed SendKeys "exit{ENTER}" 'close telnet session' SendKeys "{ENTER}" 'get command prompt back SendKeys "exit{ENTER}" 'close cmd.exe SendKeys "{ENTER}" 'get command prompt back SendKeys "exit{ENTER}" 'close cmd.exe Sub SendKeys(s) WshShell.SendKeys s WScript.Sleep 300 End Sub Sub Run(command) WshShell.Run command WScript.Sleep 100 WshShell.AppActivate command WScript.Sleep 300 End Sub
#3
1
I'm pretty sure SendKeys will not work if the desktop is locked or no user is logged in.
我很确定如果桌面被锁定或没有用户登录,SendKeys将无法工作。
#4
1
I'm pretty SendKeys will not work if you aren't logged in. It's unreliable in my experience anyway. You might be better off using a DOS batch file.
我很漂亮如果你没有登录,SendKeys将无法工作。无论如何,这在我的经验中是不可靠的。您可能最好使用DOS批处理文件。
getftpconf.bat:
telnet 10.10.40.139
netscreen
netscreen
save conf to tftp 10.10.40.139 palsg140.cf
exit
Something like that.
这样的事情。
If there is output in the command prompt that you need to record, you can put a " >> output.txt" at the end of the command line shortcut.
如果命令提示符中有需要记录的输出,则可以在命令行快捷方式的末尾添加“>> output.txt”。
You could then call another batch file which sends that output.txt via ftp to where ever you need.
然后,您可以调用另一个批处理文件,该文件通过ftp将output.txt发送到您需要的位置。
You can easily setup this batch file to run as a scheduled task in windows.
您可以轻松地将此批处理文件设置为在Windows中作为计划任务运行。
#5
1
just make a batch file that contains this:
只需创建一个包含此文件的批处理文件:
cscript.exe myscript.vbs
save it as something like myscript.bat.
将它保存为类似myscript.bat的东西。
Use schedule tasks to schedule the .bat file. After you create the scheduled task, you may have to check it's properties to make sure it's has appropriate user rights.
使用计划任务来计划.bat文件。创建计划任务后,您可能必须检查其属性以确保它具有适当的用户权限。
There are some options you can use with cscript so it doesn't show the logo, etc.
您可以使用cscript的一些选项,因此它不会显示徽标等。
#6
0
Batch files don't work in Windows with Telnet (works fine in UNIX -- again, way to go Microsoft). As already mentioned here, sendkeys does not work in vba when not logged on.
批处理文件在使用Telnet的Windows中不起作用(在UNIX中工作正常 - 再次,以微软的方式)。如前所述,sendkeys在未登录时无法在vba中运行。
Sorry I don't have the "this does work" solution for you....I'm stuck on the same problem
对不起,我没有为您提供“这项工作”解决方案....我遇到了同样的问题
#1
4
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.
添加使用您的凭据运行脚本的计划任务。提醒您自己每次更改密码时都需要更新任务的凭据。每次运行时通过电子邮件或其他东西使脚本“手机回家”是一个好主意,以便您可以判断它是否正在执行。
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.
为这些类型的活动设置单独的服务ID也是一个好主意。您可能不需要经常更改服务ID上的密码。
#2
3
You can add a scheduled task and enter no credentials or password for it. This will cause it to run under LOCAL SYSTEM (which normally is the context the Task Scheduler service uses).
您可以添加计划任务,也不输入任何凭据或密码。这将导致它在LOCAL SYSTEM(通常是Task Scheduler服务使用的上下文)下运行。
Be aware that this is a backdoor vulnerability scenario: Anyone allowed to edit your script file could misuse it to do undesirable things on the machine that runs the task. Put proper permission on the script file to prevent that. On the other hand - a task running as LOCAL SYSTEM cannot wreck havoc over the network.
请注意,这是一个后门漏洞场景:任何允许编辑脚本文件的人都可能会滥用它来在运行任务的计算机上执行不需要的操作。在脚本文件上放置适当的权限以防止这种情况。另一方面 - 作为LOCAL SYSTEM运行的任务不能破坏网络上的破坏。
I propose you condense your script file a little:
我建议你稍微压缩你的脚本文件:
Set WshShell = WScript.CreateObject("WScript.Shell") Run "cmd.exe" SendKeys "telnet 10.20.70.254{ENTER}" SendKeys "netscreen" SendKeys "{ENTER}" SendKeys "netscreen" SendKeys "{ENTER}" SendKeys "save conf to tftp 10.10.40.139 test.cfg{ENTER}" SendKeys "exit{ENTER}" 'close telnet session' Run "cmd.exe" SendKeys "telnet 10.20.70.254{ENTER}" SendKeys "netscreen" SendKeys "{ENTER}" SendKeys "netscreen" SendKeys "{ENTER}" SendKeys "save conf to tftp 10.10.40.139 palsg140.cfg{ENTER}" 'repeat as needed SendKeys "exit{ENTER}" 'close telnet session' SendKeys "{ENTER}" 'get command prompt back SendKeys "exit{ENTER}" 'close cmd.exe SendKeys "{ENTER}" 'get command prompt back SendKeys "exit{ENTER}" 'close cmd.exe Sub SendKeys(s) WshShell.SendKeys s WScript.Sleep 300 End Sub Sub Run(command) WshShell.Run command WScript.Sleep 100 WshShell.AppActivate command WScript.Sleep 300 End Sub
#3
1
I'm pretty sure SendKeys will not work if the desktop is locked or no user is logged in.
我很确定如果桌面被锁定或没有用户登录,SendKeys将无法工作。
#4
1
I'm pretty SendKeys will not work if you aren't logged in. It's unreliable in my experience anyway. You might be better off using a DOS batch file.
我很漂亮如果你没有登录,SendKeys将无法工作。无论如何,这在我的经验中是不可靠的。您可能最好使用DOS批处理文件。
getftpconf.bat:
telnet 10.10.40.139
netscreen
netscreen
save conf to tftp 10.10.40.139 palsg140.cf
exit
Something like that.
这样的事情。
If there is output in the command prompt that you need to record, you can put a " >> output.txt" at the end of the command line shortcut.
如果命令提示符中有需要记录的输出,则可以在命令行快捷方式的末尾添加“>> output.txt”。
You could then call another batch file which sends that output.txt via ftp to where ever you need.
然后,您可以调用另一个批处理文件,该文件通过ftp将output.txt发送到您需要的位置。
You can easily setup this batch file to run as a scheduled task in windows.
您可以轻松地将此批处理文件设置为在Windows中作为计划任务运行。
#5
1
just make a batch file that contains this:
只需创建一个包含此文件的批处理文件:
cscript.exe myscript.vbs
save it as something like myscript.bat.
将它保存为类似myscript.bat的东西。
Use schedule tasks to schedule the .bat file. After you create the scheduled task, you may have to check it's properties to make sure it's has appropriate user rights.
使用计划任务来计划.bat文件。创建计划任务后,您可能必须检查其属性以确保它具有适当的用户权限。
There are some options you can use with cscript so it doesn't show the logo, etc.
您可以使用cscript的一些选项,因此它不会显示徽标等。
#6
0
Batch files don't work in Windows with Telnet (works fine in UNIX -- again, way to go Microsoft). As already mentioned here, sendkeys does not work in vba when not logged on.
批处理文件在使用Telnet的Windows中不起作用(在UNIX中工作正常 - 再次,以微软的方式)。如前所述,sendkeys在未登录时无法在vba中运行。
Sorry I don't have the "this does work" solution for you....I'm stuck on the same problem
对不起,我没有为您提供“这项工作”解决方案....我遇到了同样的问题