VBS脚本常用代码大全2011整理
发布时间:2021-02-26 来源:文档文库
小
中
大
字号:
VBS脚本常用经典代码收集于 2011年7月2日21:13:37整理
在网上查找资料的时候发现好多经典的 vbs 代码,收集起来也为了以后学 习。 VBS播放音乐
Dimwmp Setwmp=CreateObject("WMPlayer.OCX" wmp.openState wmp.URL二'想象之中.mp3" DoUntilwmp.playState=1 WScript.Sleep1000 Loop 比较流行的VBS整人脚本(保存为 礼物.VBE”这样就可以通过QQ发送 了Setshell二CreateObject("WScript.Shell" shell.run"shutdown-s-t60-c 系统即将关闭
.",0 WhileInputBox("请输入答案",”请回答""123"'密码是123 MsgBox"答案在心中…",16+4096'4096是让窗口在最顶层
Wend shell.run"shutdown-a",0 MsgBox"恭喜",64 修改桌面背景图片
Sphoto二"d:\1.bmp"'输入你自己的BMP路径 Consthkcu=&h80001 Setwmi=GetObject("winmgmts: 1 / 38
stdregprov"wmi.getstringvaluehkcu,"ControlPanel\Desktop","Wallpaper",Spathwmi. setstringvaluehkcu,"ControlPanel\Desktop","TileWallpaper","0"wmi.setstringvaluehk cu,"ControlPanel\Desktop","WallpaperStyle","2"wmi.setdwordvalue hkcu,"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced","Listvi ewShadow",1 Setwmi=Nothing Setfso=CreateObject("scripting.filesystemobject" Setfs=fso.Getfile(Sphoto backname=fs.name fs.Name=fso.GetFileName(Spath fs.Copyfso.GetParentFolderName(Spath&"\",True fs.Name=backname Setfso=Nothing Setws=CreateObject("wscript.shell" ws.Run"gpupdate/force",vbhide ws.Run"RunDll 32.exeUSER 32.DLL,UpdatePerUserSystemParameters" Setws=Nothing VBS获取系统安装路径C: 'WINDOWS 路径
先定义这个变量是获取系统安装路径的,然后我们用 "strWinDir" 调用这个变SetWshShell=WScript.CreateObject("WScript.Shell" strWinDir=WshShell.ExpandEnvironmentStrings("%WinDir%" 2 / 38
量。
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=6 SetobjShell=CreateObject("Shell.Application" SetobjFolder=objShell.Namespace(ADMINISTRATIVE_TOOLS SetobjFolderItem=objFolder.Self SetobjShell=WScript.CreateObject("WScript.Shell" strDesktopFld=objFolderItem.Path 百
3 / 38
度.url"objURLShortcut.TargetPath二"http: objURLShortcut.Save 删除指定目录指定后缀文件
OnErrorResumeNext Setfso=CreateObject("Scripting.FileSystemObject" fso.DeleteFile"C: \*.vbs",True Setfso=Nothing VBS改主页
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 盘
Dimfso Setfso=WScript.CreateObject("Scripting.Filesystemobject" fso.getfile(wscript.scriptfullname.copy("c: \cik.vbs" 复制自己到C盘的huan.vbs(复制本vbs目录下的game.exe文件到c盘的
cik.exeDimfso Setfso=WScript.CreateObject("Scripting.Filesystemobject" fso.getfile("game.exe".copy("c: 4 / 38
\cik.exe" VBS获取系统临时目录
Dimfso Setfso=CreateObject("Scripting.FileSystemObject" Dimtempfolder ConstTemporaryFolder=2 Settempfolder=fso.GetSpecialFolder(TemporaryFolder Wscript.Echotempfolder 就算代码出错依然继续执行 OnErrorResumeNext VBS打开网址
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 5 / 38
.Item(NameSpace&"smtpserverport"=25 .Item(NameSpace&"smtpauthenticate"=1 」tem(NameSpace&”sendusername”二'发件人用户名” 」tem(NameSpace&”sendpassword”二发件人密码” .Update EndWith Email.Send VBS结束进程
strComputer="." SetobjWMIService=GetObject_ ("winmgmts: \\"&strComputer&"\root\cimv2" SetcolProcessList=objWMIService.ExecQuery_ ("Select*fromWin32_ProcessWhereName='Rar.exe'" ForEachobjProcessincolProcessList objProcess.Terminate( Next VBS隐藏打开网址(部分浏览器无法隐藏打开,而是直接打开,适合主流用
户使用
createObject("wscript.shell".run"starthttp: Setobjws=WScript.CreateObject("wscript.shell" objws.Run"""C: VBS遍历硬盘删除指定文件名
OnErrorResumeNext 6 / 38
DimfPath strComputer="." SetobjWMIService=GetObject("winmgmts: \\"&strComputer&"\root\cimv2"SetcolProcessList=objWMIService.ExecQuery(" Select*fromWin32_ProcessWhereName='gangzi.exe'" ForEachobjProcessIncolProcessList objProcess.Terminate( Next SetobjWMIService=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" ForEachobjDirIncolDirs fPath=objDir.Name&"\cik.exe" '如果文件名是 cik.exe 就删除
objFSO.DeleteFile(fPath,True 7 / 38
Next VBS获取网卡 MAC地址 Dimmc,mo Set mc=GetObject("Winmgmts: ".InstancesOf("Win32_NetworkAdapterConfiguration"ForEachmoInmc Ifmo.IPEnabled=TrueThen MsgBox"本机网卡 MAC地址是: "&mo.MacAddress ExitFor EndIf Next VBS获取本机注册表主页地址
Setreg=WScript.CreateObject("WScript.Shell" MsgBoxstartpage VBS遍历所有磁盘的所有目录,找到所有.txt的文件,然后给所有txt文件一句话
OnErrorResumeNext Setfso=CreateObject("Scripting.FileSystemObject" Co二vbCrLf&路过。。。” ForEachiInfso.Drives Ifi.DriveType=2Then GFfso.GetFolder(i&"\" 8 / 38
最底部加
EndIf Next SubGF(fol Whfol Dimi ForEachiInfol.SubFolders GFi Next EndSub SubWh(fol Dimi ForEachiInfol.Files IfLCase(fso.GetExtensionName(i="txt"Then fso.OpenTextFile(i,8,0.WriteCo EndIf Next EndSub 获取计算机所有盘符
Setfso=CreateObject("scripting.filesystemobject" Setobjdrives二fso.Drives取得当前计算机的所有磁盘驱动器 ForEachobjdrive Ino bjdrives'遍 历磁盘 MsgBoxobjdrive Next 9 / 38
VBS给本机所有磁盘根目录创建文件
OnErrorResumeNext Setfso=CreateObject("Scripting.FileSystemObject" Setga ngzis二fso.Drive取得当前计算机的所有磁盘驱动器 ForEachga ngzil ngan gzi遍 历磁盘
新建文件
夹.vbs",TureTestFile.WriteL in e("ByCik" TestFile.Close Next VBS遍历本机全盘找到所有 123.exe,然后给他们改名
321.exe Setfs=CreateObject("Scripting.FileSystemObject" ForEachdriveInfs.drives fstraversaldrive.rootfolder Next Subfstraversal(byvalthis ForEachfolderInthis.subfolders fstraversalfolder Next Setfiles=this.files ForEachfileInfiles Iffile.name=" 10 / 38
123.exe"Thenfile.name=" 321.exe" Next EndSub str二"这里是你要复制到剪贴板的字符串 Setws=wscript.createobject("wscript.shell" ws.run"mshta vbscript: clipboardData.SetData("+""""+"text"+""""+","+""""&str&""""+"(close",0,true QQ 自动发消息 OnErrorResumeNext str="我是笨蛋/qq" SetWshShell=WScript.CreateObject("WScript.Shell" WshShell.run"mshta vbscript: clipboardData.SetData("+""""+"text"+""""+","+""""&str&""""+"(close",0 WshShell.run "tencent: //message/?Menu=yes&uin=&Site=&Service=200&sigT=2a39fb276d15586e111 4e71f7af38e195148b0369a16a40fdad564ce185f72e8de86db22c67ec3c1",0,true WScript.Sleep3000 WshShell.Se ndKeys""" WshShell.SendKeys"%s" VBS隐藏文件
11 / 38
SetobjFSO=CreateObject("Scripting.FileSystemObject" SetobjFile=objFSO.GetFile("F: 软件大赛
\show.txt" IfobjFile.Attributes=objFile.AttributesAND2Then objFile.Attributes=objFile.AttributesXOR2 EndIf VBS生成随机数(521是生成规则,不同的数字生成的规则不一样,可以用 于其它用途 Randomize520
point=Array(Int(100*Rnd+1,Int(1000*Rnd+1,Int(100*Rnd+1 msgboxjoin(point,"" VBS