set ie=wscript.createobject("internetexplorer.application","event_") '創建ie對象'
ie.menubar=0 '取消菜單欄'
ie.addressbar=0 '取消地址欄'
ie.toolbar=0 '取消工具欄'
ie.statusbar=0 '取消狀態欄'
ie.width=400 '寬400'
ie.height=400 '高400'
ie.resizable=0 '不允許用戶改變窗口大小'
ie.navigate "about:blank" '打開空白頁面'
ie.left=fix((ie.document.parentwindow.screen.availwidth-ie.width)/2) '水平居中'
ie.top=fix((ie.document.parentwindow.screen.availheight-ie.height)/2) '垂直居中'
ie.visible=1 '窗口可見'
with ie.document '以下調用document.write方法,'
.write "html>body bgcolor=#dddddd scroll=no>" '寫一段html到ie窗口中。'
.write "h2 align=center>遠程清除系統日志/h2>br>"
.write "p>目標IP:input id=ip type=text size=15>" '也可以用navigate方法直接打開一'
.write "p>用戶名:input id=user type=text size=30>" '個html文件,效果是一樣的。'
.write "p>密碼: input id=pass type=password size=30>"
.write "p align=center>類型:" '不僅是input對象,所有DHTML支持'
.write "input id=app type=checkbox>應用程序 " '的對象及其屬性、方法都可以使用。'
.write "input id=sys type=checkbox>系統 "
.write "input id=sec type=checkbox>安全" '訪問這些對象的辦法和網頁中訪問'
.write "p align=center>br>" '框架內對象是類似的。'
.write "input id=confirm type=button value=確定> "
.write "input id=cancel type=button value=取消>"
.write "/body>/html>"
end with
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
sub clearlog(name)
wql="select * from Win32_NTEventLogFile where logfilename='"name"'"
set logs=wmi.execquery(wql) '注意,logs的成員不是每條日志,'
for each l in logs '而是指定日志的文件對象。'
if l.cleareventlog() then
wnd.alert("清除日志"name"時出錯!")
ie.quit
wscript.quit
end if
next
end sub