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

随心笔谈12个月前发布 admin
91 0

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

© 版权声明

相关文章