bat文件
set /p strinput="输入数字:" echo 输入的数字为%strinput% set /p flg="是否执行(y/n):" if "%flg%" equ "y" ( echo 执行命令 cscript abc.vbs "%strinput%" )
注意:
等于号(=)之间不能有空格,不然会出错。
判断值大小最好使用equ之类。
条件判断后的括号的有空格。
vbs文件
获取外部参数
写文件
webapi操作
日期与timestamp变换
dim wshshell dim curdir dim oparam '取参数 set oparam = wscript.arguments if oparam.count>0 then else wscript.quit end if '获取当前路径 set wshshell = wscript.createobject("wscript.shell") curdir = wshshell.currentdirectory '写文件操作 function outputdata(filename) dim objfsow dim objfilew set objfsow = wscript.createobject("scripting.filesystemobject") set objfilew = objfsow.opentextfile(filename,2,true) objfilew.write(filename) objfilew.write(vbcrlf) objfilew.write(vbtab) set objfilew = nothing set objfsow =nothing end function 'webapi操作 'params = "{""method"":""get"",""id"":""12""}" function requestapi(url,params) dim ohttp set ohttp = createobject("msxml2.serverxmlhttp") on error resume next ohttp.open "post",url,false if err then requestapi = err.description end if on error goto 0 ohttp.setrequestheader "content-type","application/json" ohttp.send params if ohttp.readystate<>4 then ohttp.waitforresponse(10) end if requestapi = ohttp.responsetext set ohttp = nothing end function 'timestamp -> date function formatdate(timestamp) formatdate = dateadd("s",clng(timestamp),"01/01/1970 00:00:00") end function 'date ->timestamp function datetotimestamp(datevalue) datetotimestamp = datediff("s","01/01/1970 00:00:00",datevalue) end function
vbs服务器bat文件,window下批处理操作:bat文件中调用vbs
@echo "kill crt process" taskkill /f /im securecrt.exe ::ping 127.0.0.1 -n 30 echo "start vos through crt" echo off d: cd d:\tools\securecrt_x86 start securecrt.exe /script d:\secure_vos\start_vos.vbs echo "start vos through crt end" ping 127.0.0.1 -n 4 pause
上述代码的意思是:在.bat文件中执行start_vos.vbs文件
批处理执行文件之前首先需要下载securecrt.exe文件
start_vos.vbs文件内容如下:
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,用户名是rootobjtab.caption = "start_vos"
将当前连接页面重命名为start_voscrt.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 # "
到此这篇关于bat文件与vbs文件之间的常用操作(获取用户输入,执行vbs文件)的文章就介绍到这了,更多相关bat获取用户输入,执行vbs文件内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论