VBS汇总

 删除文件(夹) 

createobject("scripting.filesystemobject").deletefile "文件" '要带后缀名的,不同目录要带路径 

createobject("scripting.filesystemobject").deletefolder "文件夹" '不同目录要带路径

生成其它 

set fso=createobject("scripting.filesystemobject") set 

ws=CreateObject("wscript.shell") set fw=fso.createtextfile("1.bat",2) 

fw.writeline("@echo off") fw.writeline("echo 就是这个效果") 

fw.writeline("pause") fw.close ws.run "1.bat"



VBS截取CMD返回文本

搞了很久才发现WScript.Shell有这么好的一个功能!
CODE: [Copy to clipboard]
Set objShell = CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec ("%comspec% /c " & wscript.arguments(0))
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()
loop
msgbox strText
保存为GetStdOut.vbs,在命令行里转到相应目录运行:
cscript.exe GetStdOut.vbs "ping 127.1"

看看,是不是出来了:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章