dim wmi '顯式定義一個全局變量' set wnd=ie.document.parentwindow '設置wnd為窗口對象' set id=ie.document.all '設置id為document中全部對象的集合' id.confirm.onclick=getref("confirm") '設置點擊"確定"按鈕時的處理函數' id.cancel.onclick=getref("cancel") '設置點擊"取消"按鈕時的處理函數'
do while true '由于ie對象支持事件,所以相應的,' wscript.sleep 200 '腳本以無限循環來等待各種事件。' loop
sub event_onquit 'ie退出事件處理過程' wscript.quit '當ie退出時,腳本也退出' end sub
sub cancel '"取消"事件處理過程' ie.quit '調用ie的quit方法,關閉IE窗口' end sub '隨后會觸發event_onquit,于是腳本也退出了'
sub confirm '"確定"事件處理過程,這是關鍵' with id if .ip.value="" then .ip.value="." '空ip值則默認是對本地操作' if not (.app.checked or .sys.checked or .sec.checked) then 'app等都是checkbox,通過檢測其checked' wnd.alert("至少選擇一種日志") '屬性,來判斷是否被選中。' exit sub end if set lct=createobject("wbemscripting.swbemlocator") '創建服務器定位對象' on error resume next '使腳本宿主忽略非致命錯誤' set wmi=lct.connectserver(.ip.value,"root/cimv2",.user.value,.pass.value) '連接到root/cimv2名字空間' if err.number then '自己捕捉錯誤并處理' wnd.alert("連接WMI服務器失敗") '這里只是簡單的顯示“失敗”' err.clear on error goto 0 '仍然讓腳本宿主處理全部錯誤' exit sub end if if .app.checked then clearlog "application" '清除每種選中的日志' if .sys.checked then clearlog "system" if .sec.checked then clearlog "security" '注意,在XP下有限制,不能清除安全日志' wnd.alert("日志已清除") end with end sub