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"

看看,是不是出来了:

你可能感兴趣的:(职场,vbs,删除文件,休闲,截取文本)