VBS脚本常用代码大全-2011-整理

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

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

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

资源描述

VBS脚本常用经典代码收集于2011年7月2日21:13:37整理在网上查找资料的时候发现好多经典的vbs代码,收集起来也为了以后学习。VBS播放音乐DimwmpSetwmp=CreateObject(WMPlayer.OCX)wmp.openStatewmp.URL=想象之中.mp3DoUntilwmp.playState=1WScript.Sleep1000Loop比较流行的VBS整人脚本(保存为“礼物.VBE”这样就可以通过QQ发送了)Setshell=CreateObject(WScript.Shell)shell.runshutdown-s-t60-c系统即将关闭.,0WhileInputBox(请输入答案,请回答)123'密码是123MsgBox答案在心中...,16+4096'4096是让窗口在最顶层Wendshell.runshutdown-a,0MsgBox恭喜,64修改桌面背景图片Sphoto=d:\1.bmp'输入你自己的BMP路径computer=.Consthkcu=&h80000001Setwmi=GetObject(winmgmts:\\&computer&\root\default:stdregprov)wmi.getstringvaluehkcu,ControlPanel\Desktop,Wallpaper,Spathwmi.setstringvaluehkcu,ControlPanel\Desktop,TileWallpaper,0wmi.setstringvaluehkcu,ControlPanel\Desktop,WallpaperStyle,2wmi.setdwordvaluehkcu,Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced,ListviewShadow,1Setwmi=NothingSetfso=CreateObject(scripting.filesystemobject)Setfs=fso.Getfile(Sphoto)backname=fs.namefs.Name=fso.GetFileName(Spath)fs.Copyfso.GetParentFolderName(Spath)&\,Truefs.Name=backnameSetfso=NothingSetws=CreateObject(wscript.shell)ws.Rungpupdate/force,vbhidews.RunRunDll32.exeUSER32.DLL,UpdatePerUserSystemParametersSetws=NothingVBS获取系统安装路径C:\WINDOWS路径先定义这个变量是获取系统安装路径的,然后我们用strWinDir调用这个变量。SetWshShell=WScript.CreateObject(WScript.Shell)strWinDir=WshShell.ExpandEnvironmentStrings(%WinDir%)VBS获取C:\ProgramFiles路径SetWshShell=WScript.CreateObject(WScript.Shell)strPorDir=WshShell.ExpandEnvironmentStrings(%ProgramFiles%)VBS获取C:\ProgramFiles\CommonFiles路径SetWshShell=WScript.CreateObject(WScript.Shell)strCommDir=WshShell.ExpandEnvironmentStrings(%CommonProgramFiles%)给桌面添加网址快捷方式SetWshShell=WScript.CreateObject(Wscript.Shell)strDesktop=WshShell.SpecialFolders(Desktop)SetoShellLink=WshShell.CreateShortcut(strDesktop&\百度.lnk)oShellLink.TargetPath==百度主页oShellLink.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&\百度.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,加启动项SetoShell=CreateObject(Wscript.Shell)oShell.RegWriteHKLM\Software\Microsoft\Windows\CurrentVersion\Run\cmd,cmd.exeVBS复制自己到C盘DimfsoSetfso=WScript.CreateObject(Scripting.Filesystemobject)fso.getfile(wscript.scriptfullname).copy(c:\cik.vbs)复制自己到C盘的huan.vbs(复制本vbs目录下的game.exe文件到c盘的cik.exe)DimfsoSetfso=WScript.CreateObject(Scripting.Filesystemobject)fso.getfile(game.exe).copy(c:\cik.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=这里写标题Email.Textbody=这里写内容!Email.AddAttachmentC:\这是附件.txtWithEmail.Configuration.Fields.Item(NameSpace&sendusing)=2.Item(NameSpace&smtpserver)=smtp.qq.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).runstart兼容所有浏览器,使用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&\cik.exe'如果文件名是cik.exe就删除objFSO.DeleteFile(fPath),TrueNextVBS获取网卡MAC地址Dimmc,moSetmc=GetObject(Winmgmts:).InstancesOf(Win32_NetworkAdapterConfiguration)ForEachmoInmcIfmo.IPEnabled=TrueT

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

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

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

×
保存成功