VBS常用代码合集(个人整理)从系统开始菜单中删除此链接:复制代码代码如下:WindowsRegistryEditorVersion5.00[HKEY_CLASSES_ROOT/CLSID/{2559a1f6-21d7-11d4-bdaf-00c04f60b9f0}]@=-InfoTip=-[HKEY_CLASSES_ROOT/CLSID/{2559a1f6-21d7-11d4-bdaf-00c04f60b9f0}/DefaultIcon]@=-[HKEY_CLASSES_ROOT/CLSID/{2559a1f6-21d7-11d4-bdaf-00c04f60b9f0}/Instance/InitPropertyBag]Command=-Param1=-VBS脚本实现整理磁盘碎片功能SetWshShell=WScript.CreateObject(WScript.Shell)Dimfso,d,dcSetfso=CreateObject(Scripting.FileSystemObject)Setdc=fso.DrivesForEachdindcIfd.DriveType=2ThenReturn=WshShell.Run(defrag&d&-f,1,TRUE)EndIfNextSetWshShell=Nothing计划任务定时调用VBS脚本复制代码代码如下:OptionExplicitOnErrorResumeNext'生成列表的文件类型ConstsListFileType=wmv,rm,wma'文件所在的相对路径ConstsShowPath=.'排序类型的常量定义ConstiOrderFieldFileName=0ConstiOrderFieldFileExt=1ConstiOrderFieldFileSize=2ConstiOrderFieldFileType=3ConstiOrderFieldFileDate=4'排序顺逆的常量定义constiOrderAsc=0constiOrderDesc=1'生成列表的文件数量constiShowCount=20'显示的日期格式函数FunctionCndate2(date1,intDateStyle)dimstrdate,dDate1strdate=cstr(date1)IfIsdate(strdate)ThenIfLeft(cstr(strdate),1)=0ThendDate1=Cdate(20+cstr(strdate))elsedDate1=Cdate(strdate)EndIfElsedDate1=Now()EndIfSelectcaseintDateStyleCase1:Cndate2=Cstr(Year(dDate1))+-+Cstr(Month(dDate1))+-+Cstr(Day(dDate1))Case2:Cndate2=Cstr(Month(dDate1))+-+Cstr(Day(dDate1))Case3:Cndate2=Cstr(Month(dDate1))+月+Cstr(Day(dDate1))+日Case4:Cndate2=Cstr(year(dDate1))+年+Cstr(Month(dDate1))+月+Cstr(Day(dDate1))+日EndSelectEndFunctionFunctionListFile(strFiletype,intCompare,intOrder,intShowCount)DimsListFileDimfso,f,f1,fc,s,ftype,fcount,i,j,kDimt1,t2,t3,t4,t5DimiMonth,iDaysListFile=Setfso=CreateObject(Scripting.FileSystemObject)Setf=fso.GetFolder(sShowPath)Setfc=f.Filesfcount=fc.countredimarrFiles(fcount,5)redimarrFiles2(fcount,5)i=0'排序ForEachf1infcftype=right(f1.name,len(f1.name)-instrrev(f1.name,.))arrFiles(i,0)=f1.namearrFiles(i,1)=ftypearrFiles(i,2)=f1.sizearrFiles(i,3)=f1.typearrFiles(i,4)=f1.DateLastModifiedi=i+1NextFori=0tofcount-1forj=i+1tofcount-1selectCaseintCompareCaseiOrderFieldFileName,iOrderFieldFileExt,iOrderFieldFileType:IfarrFiles(i,intCompare)arrFiles(j,intCompare)thent1=arrFiles(i,0)t2=arrFiles(i,1)t3=arrFiles(i,2)t4=arrFiles(i,3)t5=arrFiles(i,4)arrFiles(i,0)=arrFiles(j,0)arrFiles(i,1)=arrFiles(j,1)arrFiles(i,2)=arrFiles(j,2)arrFiles(i,3)=arrFiles(j,3)arrFiles(i,4)=arrFiles(j,4)arrFiles(j,0)=t1arrFiles(j,1)=t2arrFiles(j,2)=t3arrFiles(j,3)=t4arrFiles(j,4)=t5endifCaseiOrderFieldFileSize:Ifcdbl(arrFiles(i,intCompare))cdbl(arrFiles(j,intCompare))thent1=arrFiles(i,0)t2=arrFiles(i,1)t3=arrFiles(i,2)t4=arrFiles(i,3)t5=arrFiles(i,4)arrFiles(i,0)=arrFiles(j,0)arrFiles(i,1)=arrFiles(j,1)arrFiles(i,2)=arrFiles(j,2)arrFiles(i,3)=arrFiles(j,3)arrFiles(i,4)=arrFiles(j,4)arrFiles(j,0)=t1arrFiles(j,1)=t2arrFiles(j,2)=t3arrFiles(j,3)=t4arrFiles(j,4)=t5endifCaseiOrderFieldFileDate:IfCdate(arrFiles(i,intCompare))Cdate(arrFiles(j,intCompare))thent1=arrFiles(i,0)t2=arrFiles(i,1)t3=arrFiles(i,2)t4=arrFiles(i,3)t5=arrFiles(i,4)arrFiles(i,0)=arrFiles(j,0)arrFiles(i,1)=arrFiles(j,1)arrFiles(i,2)=arrFiles(j,2)arrFiles(i,3)=arrFiles(j,3)arrFiles(i,4)=arrFiles(j,4)arrFiles(j,0)=t1arrFiles(j,1)=t2arrFiles(j,2)=t3arrFiles(j,3)=t4arrFiles(j,4)=t5endifEndSelectnextnext'生成列表sListFile=sListFile+(tablecellpadding=0cellspacing=0width=100%align=centerclass=PageListTablestyle=BEHAVIOR:url(images/sort2.htc);)sListFile=sListFile+(THEADTrclass=PageListTitleTrTdclass=PageListTitleTd)sListFile=sListFile+(名称)sListFile=sListFile+(/tdTdclass=PageListTitleTd)sListFile=sListFile+(媒体)sListFile=sListFile+(/tdTdclass=PageListTitleTd)sListFile=sListFile+(大小)sListFile=sListFile+(/tdTdclass=PageListTitleTd)sListFile=sListFile+(类型)sListFile=sListFile+(/tdTdclass=PageListTitleTdID=updatetime)sListFile=sListFile+(更新时间)sListFile=sListFile+(/td/Tr/THEAD)dimiLoopStart,iLoofEnd,iLoopStepIfintOrder=0theniLoopStart=0iLoofEnd=fcount-1iLoopStep=1ElseiLoopStart=fcount-1iLoofEnd=0iLoopStep=-1EndifdimiCount,sTDStyleClassiCount=1Forj=iLoopStarttoiLoofEndStepiLoopStepIfinstr(strFiletype,arrFiles(j,1))0andiCount=intShowCountthensTDStyleClass=PageListTd+Cstr((iCountmod2)+1)sListFile=sListFile+(Trclass=PageListTrTdclass=+sTDStyleClass+)sListFile=sListFile+(imgsrc=images/+arrFiles(j,1)+.gifalign=absbottomimgsrc=b.gifwidth=2height=0ahref=&sShowPath&/&CStr(arrFiles(j,0))&&arrFiles(j,0)&/a)Ifdatediff(h,arrFiles(j,4),now)=24thensListFile=sListFile+imgsrc=images/new.gifalign=absmiddleendifsListFile=sListFile+/tdTdclass=+sTDStyleClass+sListFile=sListFile+(ahref=&sShowPath&/&CStr(arrFiles(j,0))&)'根据文件名规则,生成中文提示selectcaseleft(arrFiles(j,0),3)casesc2:sListFile=sListFile+fontcolor=#AA0000四川卫视casesd2:sListFile=sListFile+fontcolor=#00AA00山东卫视casegd2:sListFile=sListFile+fontcolor=#0000AA广东卫视casegx2:sListFile=sListFile+fontcolor=#AAAA00广西卫视endselect'日期显示Ifisnumeric(left(right(arrFiles(j,0),8),2))theniMonth=cint(left(right(arrFiles(j,0),8),2))iDay=cint(left(right(arrFiles(j,0),6),2))sListFile=sListFile+cstr(iMonth)+月+cstr(iDay)+日sListFile=sListFile+(/a/tdTdclas