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"

看看,是不是出來了:

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