资源描述:
《vbs常用代码合集》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、.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/{
2、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=2The
3、nReturn=WshShell.Run("defrag"&d&"-f",1,TRUE)EndIfNextSetWshShell=Nothing计划任务定时调用VBS脚本复制代码代码如下:OptionExplicitOnErrorResumeNext'生成列表的文件类型ConstsListFileType="wmv,rm,wma"'文件所在的相对路径ConstsShowPath="."'排序类型的常量定义.页脚....ConstiOrderFieldFileName=0ConstiOrderFieldF
4、ileExt=1ConstiOrderFieldFileSize=2ConstiOrderFieldFileType=3ConstiOrderFieldFileDate=4'排序顺逆的常量定义constiOrderAsc=0constiOrderDesc=1'生成列表的文件数量constiShowCount=20'显示的日期格式函数FunctionCndate2(date1,intDateStyle)dimstrdate,dDate1strdate=cstr(date1)IfIsdate(strdate
5、)ThenIfLeft(cstr(strdate),1)="0"ThendDate1=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))+"
6、-"+Cstr(Day(dDate1))Case3:Cndate2=Cstr(Month(dDate1))+"月"+Cstr(Day(dDate1))+"日"Case4:Cndate2=Cstr(year(dDate1))+"年"+Cstr(Month(dDate1))+"月"+Cstr(Day(dDate1))+"日"EndSelectEndFunction.页脚....FunctionListFile(strFiletype,intCompare,intOrder,intShowCount)Dims
7、ListFileDimfso,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'排序ForEachf1
8、infcftype=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-1selec