on error resume next '设置当程序执行出现问题时直接跳转到下一条指令
set s=createobject("wscript.shell") '把wscript脚本执行外壳特性赋予给 os
set f=createobject("scripting.filesystemobject") '---把文件系统管理功能特性赋予给 f
sysd=os.ExpandEnvironmentStrings("%systemdrive%") '---获取系统所在分区的盘符
dim name(4) '---以下5行分别把系统各固定用户名和当前用户名赋值给 数组 name
name(0)="all users"
name(1)="default user"
name(2)="localservice"
name(3)="networkservice"
name(4)=os.ExpandEnvironmentStrings("%username%")
set fc=f.createtextfile("deltemp.txt") '创建文本文件 deltemp.txt
for each namex in name
'此行以及以下6行用于根据数组 name 把系统中用户对应的固定缓存文件夹名称传递给deltemp.txt 文件
fc.writeline(sysd&"\Documents and Settings\"&namex&"\Local Settings\temp")
fc.writeline(sysd&"\Documents and Settings\"&namex&"\Cookies")
fc.writeline(sysd&"\Documents and Settings\"&namex&"\Local Settings\Temporary Internet Files")
fc.writeline(sysd&"\Documents and Settings\"&namex&"\Recent")
fc.writeline(sysd&"\Documents and Settings\"&namex&"\Local Settings\History")
next
net_temp=os.regread("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\cache") '---通过读取注册表特殊位置获知系统ie浏览器的缓存文件夹位置,并赋值给变量net_temp
if trim(net_temp)<>"" then fc.writeline(net_temp)
'---用于判断变量 net_temp 所带包的文件夹是否为空,如果不为空就将其内容添加到deltemp.txt中
fc.writeline(os.ExpandEnvironmentStrings("%temp%"))
'---将当前用户的临时缓存文件夹位置添加到 deltemp.txt 中
fc.close '关闭deltemp.txt 文件
r=os.run("cmd /c echo "&os.Environment("system")("temp")&" >>deltemp.txt",0,true)
'---将system系统级别的临时缓存文件夹位置添加到 deltemp.txt 中
'---因为os.Environment("system")("temp") 所得出的内容包含只有 cmd.exe 可以识别的 %% ,所以必须‘用 cmd 完成该内容的文件写入。
'---又因为cmd 属于vbs 外部程序,所以在进行统一文件的写入之前,必须事先在vbs中关闭此文件,这‘里指的就是 deltemp.txt
set fread=f.opentextfile("deltemp.txt",1,false)
'---以读取方式打开文本文件 deltemp 其中 1 表示 forreading ,2 表示 forwriting ,8 表示addforwriting
'---同时把文件 deltemp.txt 的特性和指令赋予给 fread
do until fread.atendofline '---删除 deltemp.txt 文件中所记载的缓存文件夹
path=trim(fread.readline) '---从deltemp读取一条信息,并取掉前后空格以后,赋值给变量 path
set path1=f.getfolder(path) '---将 path 所代表的文件夹特性赋予给 path1
'---以下循环通过 del_pf 子程序对目标文件夹其下2层子目录进行清理
for each path2 in path1.subfolders '---对path1所代表的文件夹中的子目录进行逐一操作
for each path3 in path2.subfolders '---对path2所代表的文件夹中的子目录进行逐一操作
del_pf(path3) '---调用 子程序 del_pf() 对 path3 所代表的文件夹进行删除操作
next
del_pf(path2)
next
del_pf(path1)
loop
QTP_Msgbox "系统缓存清理完毕!",2,"清除IE缓存、上网痕迹"
'---弹出清理完毕的窗口
fread.close '---关闭文件 deltemp.txt
f.deletefile "deltemp.txt",true '---删除文件 deltemp.txt
wscript.quit '---退出
'----------------------------------
sub del_pf(pf) '子程序 del_pf 用来删除指定文件夹中的子目录和文件
on error resume next
set f=CreateObject("Scripting.FileSystemObject")
set pfs=f.getFolder(pf)
for each ff in pfs.files
del=f.deletefile(ff,true)
next
for each pp in pfs.subfolders
del=f.deletefolder(pp,true)
next
end sub
'定时停留弹出框函数
Sub QTP_Msgbox(Text,waitTime,Title)
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Popup Text, waitTime, Title
Set WshShell = nothing
End Sub