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