- ·上一篇文章:中国象棋也可以用批处理来做
- ·下一篇文章:批处理代码写的一键转移桌面-收藏夹-文档多用户版
- ·百度中搜索更多的关于“用VBS脚本对文件夹实时监控”相关内容
- ·谷歌中搜索更多的关于“用VBS脚本对文件夹实时监控”相关内容
- ******申明******
- 本站文章内容有部分为收录网络中其他网友内容,DOS资源站不保证所有的代码都适合你使用。
- 由于编辑匆忙,有可能造成某些脚本文件出现丢失代码或代码无法运行的情况,请网友根据情况自行修改。
- 如果能将出错部分反馈给我,那就更好了。
用VBS脚本对文件夹实时监控
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

