千家信息网

window下批处理操作:bat文件中调用vbs

发表于:2025-01-31 作者:千家信息网编辑
千家信息网最后更新 2025年01月31日,@echo "kill CRT process"taskkill /F /IM SecureCRT.exe::ping 127.0.0.1 -n 30echo "start vos through C
千家信息网最后更新 2025年01月31日window下批处理操作:bat文件中调用vbs
@echo "kill CRT process"taskkill /F /IM SecureCRT.exe::ping 127.0.0.1 -n 30echo "start vos through CRT"echo offd:cd D:\tools\SecureCRT_x86start SecureCRT.EXE /SCRIPT D:\Secure_vos\Start_vos.vbsecho "start vos through CRT end"ping 127.0.0.1 -n 4pause

上述代码的意思是:在.bat文件中执行Start_vos.vbs文件

批处理执行文件之前首先需要下载SecureCRT.exe文件

Start_vos.vbs文件内容如下:

#$language = "VBScript"#$interface = "1.0"crt.Screen.Synchronous = TrueSub Main        On Error Resume Next        Dim result        If crt.Session.Connected Then crt.Session.Disconnect' connected to the '172.21.1.114'                      Set objtab = crt.Session.ConnectInTab("/SSH2 /PASSWORD root root@172.21.1.114",True)' Capture error code and description (if any)        nError = Err.Number        strErr = Err.Description' Now, tell the script host that it should handle errors as usual now:        On Error Goto 0' change tab name        objtab.caption = "Gdb_vos"        ' enter the folder        crt.Screen.Send "cd /home/test" & chr(13)        crt.Screen.WaitForString chr(27) & "[32m(none) /home/test" & chr(27) & "[m # "End Sub

上述代码主要是将手动输入的过程使用VBS脚本进行自动化

首先:

Set objtab = crt.Session.ConnectInTab("/SSH2 /PASSWORD root123 root@172.11.1.15",True)

采用SSH2的方式连接linuxIP地址

172.21.1.114,密码是root123,用户名是root
objtab.caption = "Start_vos"

将当前连接页面重命名为Start_vos

crt.Screen.Send "cd /home/test" & chr(13)
输入cd /home/test并回车
crt.Screen.WaitForString chr(27) & "[32m(none) /home/test" & chr(27) & "[m # "
等待页面下一行的内容为
chr(27) & "[32m(none) /home/test" & chr(27) & "[m # "


0