'*********************************************** '用COM對象scripting.FileSystemObject操作文本文件 '*********************************************** Set fs = Wscript.CreateObject("scripting.FileSystemObject") Set a = fs.CreateTextFile("c:/testfile.txt", True) a.WriteLine("這是一個測試。") a.Close
也可以在asp等web編程語言中應用 <script language="VBscript.Encode" runat=server> '上面用SHELL對象啟動程序 Set WshShell = server.CreateObject("Wscript.Shell") IsSuccess = WshShell.Run ("D:/winnt/system32/cmd.exe" ,1, true) if IsSuccess = 0 Then Response.write " 命令成功執行!" else Response.write " 命令執行失敗!權限不夠或者該程序無法在DOS狀態下運行" end if </script> 注: 1.其中runat=server必須要有 2.Set WshShell = Wscript.CreateObject("Wscript.Shell") 要改為Set WshShell = server.CreateObject("Wscript.Shell"), 3.參數1代表SW_SHOWNORMAL, 激活并顯示一個窗口。若窗口是最小化或最大化,則恢復到其原來的大小和位置。 4.TRUE代表返回執行的錯誤,False或者為指定代表腳本繼續執行而不等待進程結束。 5.調用WSH的內置對象了,可以象調用函數和過程一樣。 如call WshShell.Run ("D:/winnt/system32/cmd.exe" ,1, true)
現在我們言歸正傳來看看如何對文件進行壓縮和解壓! 大家都知道winzip對文件解壓和壓縮都易如反掌,但是如何通過程序和命令行對其調用呢? 當然winzip的作者已經開發出 WinZip Command Line Support Add-On Version 1.0 大家去可以去http://www.winzip.com/wzcline.htm 下載wzcline.exe! 前提是本機須安裝winzip8.0或更高版本的支持,如果你不是winzip8.0,去 http://www.winzip.com/download.htm 下載!