这篇“bat文件与Vbs文件间的常用操作方法有哪些”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“bat文件与Vbs文件间的常用操作方法有哪些”文章吧。
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 WshShellDim CurDirDim oParam'取参数Set oParam = WScript.Argumentsif oParam.Count>0 ThenElse WScript.QuitEnd 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 =NothingEnd 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 = NothingEnd Function'TimeStamp -> DateFunction FormatDate(timestamp) FormatDate = DateAdd("s",CLng(timestamp),"01/01/1970 00:00:00")End Function'Date ->TimeStampFunction 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 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文件内容如下:
On Error Resume NextDim resultIf 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.NumberstrErr = Err.Description' Now, tell the script host that it should handle errors as usual now:On Error Goto 0' change tab nameobjtab.caption = "Gdb_vos"' enter the foldercrt.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文件间的常用操作方法有哪些”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注编程网行业资讯频道。