nbsp;'空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
总结一下整个过程。首先是创建internetexplorer.application对象。其直接的效果是启动了一个iexplorer进程,但窗口是不可见的,直到设置了ie.visible=1。然后用document.write方法将html语句写到ie窗口中。对于复杂的界面,可以将html代码保存为一个html文件,用ie.navigate(filename)打开。最后是响应窗口中的输入。这基本上属于DHTML的知识范畴。
与一般脚本编程最大的不同之处,在于ie是事件驱动的。你所要做的,就是设置好相应的事件处理函数/过程。
在
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
总结一下整个过程。首先是创建internetexplorer.application对象。其直接的效果是启动了一个iexplorer进程,但窗口是不可见的,直到设置了ie.visible=1。然后用document.write方法将html语句写到ie窗口中。对于复杂的界面,可以将html代码保存为一个html文件,用ie.navigate(filename)打开。最后是响应窗口中的输入。这基本上属于DHTML的知识范畴。
与一般脚本编程最大的不同之处,在于ie是事件驱动的。你所要做的,就是设置好相应的事件处理函数/过程。
在
| 对此文章发表了评论 |

