VBS脚本常用经典代码收集

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

VBS脚本常用经典代码收集标签:转载未验证转载自:在网上查找资料的时候发现好多经典的vbs代码,收集起来也为了以后学习。VBS脚本用途很多:1.计算2.处理文件和文件夹3.管理Windows4.处理Word,Excel,PowerPoint等Office文档5.嵌入网页,驱动dHTML6.编写HTTP通信7.调用系统功能(COM组件),比如说语音说话8.分析HTML,XML9.调用命令行并分析返回结果10.处理图片11.自动化按键12.调用WindowsMediaPlayer并管理13.调用WindowsLiveMessenger并管理14.服务端技术:ActiveServerPage(ASP)15.脚本病毒16.处理数据库下面是我收集的VBS代码,大部分转自gangzi.org,以后还会更新。VBS获取系统安装路径先定义这个变量是获取系统安装路径的,然后我们用”&strWinDir&”调用这个变量。setWshShell=WScript.CreateObject(WScript.Shell)strWinDir=WshShell.ExpandEnvironmentStrings(%WinDir%)VBS获取C:\ProgramFiles路径msgboxCreateObject(WScript.Shell).ExpandEnvironmentStrings(%ProgramFiles%)VBS获取C:\ProgramFiles\CommonFiles路径msgboxCreateObject(WScript.Shell).ExpandEnvironmentStrings(%CommonProgramFiles%)给桌面添加网址快捷方式setgangzi=WScript.CreateObject(WScript.Shell)strDesktop=gangzi.SpecialFolders(Desktop)setoShellLink=gangzi.CreateShortcut(strDesktop&\InternetExplorer.lnk)oShellLink.TargetPath==InternetExploreroShellLink.IconLocation=%ProgramFiles%\InternetExplorer\iexplore.exe,0oShellLink.Save给收藏夹添加网址ConstADMINISTRATIVE_TOOLS=6SetobjShell=CreateObject(Shell.Application)SetobjFolder=objShell.Namespace(ADMINISTRATIVE_TOOLS)SetobjFolderItem=objFolder.SelfSetobjShell=WScript.CreateObject(WScript.Shell)strDesktopFld=objFolderItem.PathSetobjURLShortcut=objShell.CreateShortcut(strDesktopFld&\奋斗Blog.url)objURLShortcut.TargetPath=删除指定目录指定后缀文件OnErrorResumeNextSetfso=CreateObject(Scripting.FileSystemObject)fso.DeleteFileC:\*.vbs,TrueSetfso=NothingVBS改主页SetoShell=CreateObject(WScript.Shell)oShell.RegWriteHKEY_CURRENT_USER\Software\Microsoft\InternetExplorer\Main\StartPage,=CreateObject(Wscript.Shell)oShell.RegWriteHKLM\Software\Microsoft\Windows\CurrentVersion\Run\cmd,cmd.exeVBS复制自己setcopy1=createobject(scripting.filesystemobject)copy1.getfile(wscript.scriptfullname).copy(c:\huan.vbs)复制自己到C盘的huan.vbs(复制本vbs目录下的game.exe文件到c盘的gangzi.exe)setcopy1=createobject(scripting.filesystemobject)copy1.getfile(game.exe).copy(c:\gangzi.exe)VBS获取系统临时目录DimfsoSetfso=CreateObject(Scripting.FileSystemObject)DimtempfolderConstTemporaryFolder=2Settempfolder=fso.GetSpecialFolder(TemporaryFolder)Wscript.Echotempfolder就算代码出错依然继续执行OnErrorResumeNextVBS打开网址SetobjShell=CreateObject(Wscript.Shell)objShell.Run()VBS发送邮件NameSpace==CreateObject(CDO.Message)Email.From=发件@qq.comEmail.To=收件@qq.comEmail.Subject=Testsendmail.vbsEmail.Textbody=OK!Email.AddAttachmentC:\1.txtWithEmail.Configuration.Fields.Item(NameSpace&sendusing)=2.Item(NameSpace&smtpserver)=smtp.邮件服务器.com.Item(NameSpace&smtpserverport)=25.Item(NameSpace&smtpauthenticate)=1.Item(NameSpace&sendusername)=发件人用户名.Item(NameSpace&sendpassword)=发件人密码.UpdateEndWithEmail.SendVBS结束进程strComputer=.SetobjWMIService=GetObject_(winmgmts:\\&strComputer&\root\cimv2)SetcolProcessList=objWMIService.ExecQuery_(Select*fromWin32_ProcessWhereName='Rar.exe')ForEachobjProcessincolProcessListobjProcess.Terminate()NextVBS隐藏打开网址(部分浏览器无法隐藏打开,而是直接打开,适合主流用户使用)createObject(wscript.shell).runiexplore兼容所有浏览器,使用IE的绝对路径+参数打开,无法用函数得到IE安装路径,只用函数得到了ProgramFiles路径,应该比上面的方法好,但是两种方法都不是绝对的。Setobjws=WScript.CreateObject(wscript.shell)objws.RunC:\ProgramFiles\InternetExplorer\iexplore.exe遍历硬盘删除指定文件名OnErrorResumeNextDimfPathstrComputer=.SetobjWMIService=GetObject_(winmgmts:\\&strComputer&\root\cimv2)SetcolProcessList=objWMIService.ExecQuery_(Select*fromWin32_ProcessWhereName='gangzi.exe')ForEachobjProcessincolProcessListobjProcess.Terminate()NextSetobjWMIService=GetObject(winmgmts:_&{impersonationLevel=impersonate}!\\&strComputer&\root\cimv2)SetcolDirs=objWMIService._ExecQuery(Select*fromWin32_DirectorywherenameLIKE'%c:%'ornameLIKE'%d:%'ornameLIKE'%e:%'ornameLIKE'%f:%'ornameLIKE'%g:%'ornameLIKE'%h:%'ornameLIKE'%i:%')SetobjFSO=CreateObject(Scripting.FileSystemObject)ForEachobjDirincolDirsfPath=objDir.Name&\gangzi.exeobjFSO.DeleteFile(fPath),TrueNextVBS获取网卡MAC地址Dimmc,moSetmc=GetObject(Winmgmts:).InstancesOf(Win32_NetworkAdapterConfiguration)ForEachmoInmcIfmo.IPEnabled=TrueThenMsgBox本机网卡MAC地址是:&mo.MacAddressExitForEndIfNextVBS获取本机注册表主页地址Setreg=WScript.CreateObject(WScript.Shell)startpage=reg.RegRead(HKEY_CURRENT_USER\Software\Microsoft\InternetExplorer\Main\StartPage)MsgBoxstartpageVBS遍历所有磁盘的所有目录,找到所有.txt的文件,然后给所有txt文件最底部加一句话OnErrorResumeNextSetfso=CreateObject(Scripting.FileSystemObject)Co=VbCrLf&路过。。。ForEachiInfso.DrivesIfi.DriveType=2ThenGFfso.GetFolder(i&\)EndIfNextSubGF(fol)WhfolDimiForEachiInfol.SubFoldersGFiNextEndSubSubWh(fol)DimiForEachiInfol.FilesIfLCase(fso.GetExtensionName(i))=shtmlThenfso.OpenTextFile(i,8,0).WriteCoEndIfNextEndSub获取计算机所有盘符Setfso=CreateObject(scripting.filesystemobject)Setobjdrives=fso.Drives'取得当前计算机的所有磁盘驱动器ForEachobjdriveInobjdrives'遍历磁盘MsgBoxobjdriveNextVBS给本机所有磁盘根目录创建文件OnErrorResumeNextSetfso=CreateObjec

1 / 20
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功