当前位置:DOS资源站资料中心VBS脚本 → 用VBS脚本对文件夹实时监控

用VBS脚本对文件夹实时监控

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2008-4-26 19:45:39

a=msgbox("是否开始监控文件夹??",1,"後知後覺")
if a=1 then
dim strname,wmi
strname="."
set wmi=getobject("winmgmts:\\"&strname&"\root\cimv2")
set sink=wscript.createobject("wbemscripting.swbemsink","sink_")
wmi.execnotificationqueryasync sink, _
("SELECT * FROM __InstanceCreationEvent WITHIN 1 where " _
& "Targetinstance ISA 'win32_subdirectory' and " _ 
& "TargetInstance.groupcomponent= " _
& "'Win32_Directory.Name=""c:\\\\windows""' or " _
& "Targetinstance ISA 'cim_directorycontainsfile' and " _
& "TargetInstance.groupcomponent= " _
& "'Win32_Directory.Name=""c:\\\\windows""'")
do
wscript.sleep 1000
loop
sub sink_onobjectready(objlatestevent,objasynccontext)
mypath=objlatestevent.targetinstance.PartComponent
mys=instrrev(mypath,"\")
i=right(mypath,len(mypath)-mys)
set fso=createobject("scripting.filesystemobject")
if MsgBox("""" &i & "删除吗?", vbYesNo+vbQuestion, "文件监控") = vbYes then
if instr(i,".")="0" then
fso.deletefolder "c:\windows\"&i,true
else
fso.deletefile "c:\windows\"&i,true
end if
end if
end sub
else
msgbox "已放弃监控。",64,"消息:"
end if