BATCH+VBS腳本自動執行命令
阿新 • • 發佈:2018-07-01
執行命令 system com mps RM ros amp AR pau
打開cmd,然後執行run.bat s 1就會執行tmpsw.vbs的內容,1是作為id傳進去的參數。
run.bat:
@echo off set type=%1 set id=%2 :打開一個telnet start "%id%" "telnet" If "%type%" EQU "s" ( @echo "switch" cscript //nologo tmpsw.vbs %id% ) else ( if "%type%" EQU "r" ( @echo "router" cscript //nologo tmpr.vbs %id% ) else ( @echo "pc" cscript //nologo tmp.vbs %id% ) ) pause
拿某個vbs為例,可以幫我們自動執行一些命令:
tmp.vbs:
Set args = WScript.Arguments If args.Count = 1 Then id=WScript.Arguments(0) End If port=id+3000 ip=id&".1.202.1" set sh=WScript.CreateObject("WScript.Shell") WScript.Sleep 100 sh.SendKeys "o localhost "&port&"{ENTER}" WScript.Sleep 1000 sh.SendKeys "{ENTER}" WScript.Sleep 10 sh.SendKeys "no{ENTER}" WScript.Sleep 10 sh.SendKeys "{ENTER}" sh.SendKeys "{ENTER}" sh.SendKeys "en{ENTER}" sh.SendKeys "{ENTER}" WScript.Sleep 10 sh.SendKeys "conf t{ENTER}" WScript.Sleep 10 sh.SendKeys "host SW"&id&"{ENTER}"
關於SendKeys
BATCH+VBS腳本自動執行命令