Content

bat文件与Vbs文件之间的常用操作(获取用户输入,执行VBS文件)(vbs调用批处理)一看就会

文章摘要

这篇文章介绍了作者自定义的Windows脚本模块,主要用于处理文件操作和WebAPI请求。模块包含以下主要功能: 1. **OutputData函数**:负责将数据写入指定的文本文件,并在每行末尾添加换行符和制表符。 2. **RequestAPI函数**:实现对Web服务的POST请求,处理错误并返回响应文本。 3. **FormatDate和DateToTimeStamp函数**:用于时间戳和日期的转换。 文章整体展示了如何利用自定义脚本完成数据写入和Web服务调用,适用于自动化和Web开发任务。

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=”” 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