码迷,mamicode.com
首页 > 其他好文 > 详细

BATCH+VBS脚本自动执行命令

时间:2018-07-01 01:06:19      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:host   logo   tps   soft   tmp   TE   art   ndk   自动   

打开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脚本自动执行命令

标签:host   logo   tps   soft   tmp   TE   art   ndk   自动   

原文地址:https://www.cnblogs.com/flipped/p/9249162.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!