VBS脚本常用经典代码收集Word文件下载.docx
《VBS脚本常用经典代码收集Word文件下载.docx》由会员分享,可在线阅读,更多相关《VBS脚本常用经典代码收集Word文件下载.docx(21页珍藏版)》请在冰豆网上搜索。
%ProgramFiles%"
\ProgramFiles\CommonFiles路径
%CommonProgramFiles%"
给桌面添加网址快捷方式
setgangzi=WScript.CreateObject("
strDesktop=gangzi.SpecialFolders("
Desktop"
setoShellLink=gangzi.CreateShortcut(strDesktop&
"
\InternetExplorer.lnk"
oShellLink.TargetPath="
http:
//www.fendou.info"
oShellLink.Description="
InternetExplorer"
oShellLink.IconLocation="
%ProgramFiles%\InternetExplorer\iexplore.exe,0"
oShellLink.Save
给收藏夹添加网址
ConstADMINISTRATIVE_TOOLS=6
SetobjShell=CreateObject("
Shell.Application"
SetobjFolder=objShell.Namespace(ADMINISTRATIVE_TOOLS)
SetobjFolderItem=objFolder.Self
SetobjShell=WScript.CreateObject("
strDesktopFld=objFolderItem.Path
SetobjURLShortcut=objShell.CreateShortcut(strDesktopFld&
\奋斗Blog.url"
objURLShortcut.TargetPath="
//www.fendou.info/"
objURLShortcut.Save
删除指定目录指定后缀文件
OnErrorResumeNext
Setfso=CreateObject("
Scripting.FileSystemObject"
fso.DeleteFile"
C:
\*.vbs"
True
Setfso=Nothing
VBS改主页
SetoShell=CreateObject("
oShell.RegWrite"
HKEY_CURRENT_USER\Software\Microsoft\InternetExplorer\Main\StartPage"
"
VBS加启动项
SetoShell=CreateObject("
Wscript.Shell"
HKLM\Software\Microsoft\Windows\CurrentVersion\Run\cmd"
cmd.exe"
VBS复制自己
setcopy1=createobject("
scripting.filesystemobject"
copy1.getfile(wscript.scriptfullname).copy("
c:
\huan.vbs"
复制自己到C盘的huan.vbs(复制本vbs目录下的game.exe文件到c盘的gangzi.exe)
copy1.getfile("
game.exe"
).copy("
\gangzi.exe"
VBS获取系统临时目录
Dimfso
Dimtempfolder
ConstTemporaryFolder=2
Settempfolder=fso.GetSpecialFolder(TemporaryFolder)
Wscript.Echotempfolder
就算代码出错依然继续执行
VBS打开网址
objShell.Run("
VBS发送邮件
NameSpace="
SetEmail=CreateObject("
CDO.Message"
Email.From="
发件@"
Email.To="
收件@"
Email.Subject="
Testsendmail.vbs"
Email.Textbody="
OK!
"
Email.AddAttachment"
\1.txt"
WithEmail.Configuration.Fields
.Item(NameSpace&
sendusing"
)=2
smtpserver"
)="
smtp.邮件服务器.com"
smtpserverport"
)=25
smtpauthenticate"
)=1
sendusername"
发件人用户名"
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"
iexplorehttp:
0
兼容所有浏览器,使用IE的绝对路径+参数打开,无法用函数得到IE安装路径,只用函数得到了ProgramFiles路径,应该比上面的方法好,但是两种方法都不是绝对的。
Setobjws=WScript.CreateObject("
objws.Run"
\ProgramFiles\InternetExplorer\iexplore.exe"
vbhide
VBS遍历硬盘删除指定文件名
DimfPath
gangzi.exe'
SetobjWMIService=GetObject("
_
&
{impersonationLevel=impersonate}!
SetcolDirs=objWMIService._
ExecQuery("
Select*fromWin32_DirectorywherenameLIKE'
%c:
%'
ornameLIKE'
%d:
%e:
%f:
%g:
%h:
%i:
SetobjFSO=CreateObject("
ForEachobjDirincolDirs
fPath=objDir.Name&
objFSO.DeleteFile(fPath),True
VBS获取网卡MAC地址
Dimmc,mo
Setmc=GetObject("
Winmgmts:
).InstancesOf("
Win32_NetworkAdapterConfiguration"
ForEachmoInmc
Ifmo.IPEnabled=TrueThen
MsgBox"
本机网卡MAC地址是:
mo.MacAddress
ExitFor
EndIf
VBS获取本机注册表主页地址
Setreg=WScript.CreateObject("
startpage=reg.RegRead("
MsgBoxstartpage
VBS遍历所有磁盘的所有目录,找到所有.txt的文件,然后给所有txt文件最底部加一句话
Co=VbCrLf&
路过。
。
ForEachiInfso.Drives
Ifi.DriveType=2Then
GFfso.GetFolder(i&
\"
EndIf
SubGF(fol)
Whfol
Dimi
ForEachiInfol.SubFolders
GFi
Next
EndSub
SubWh(fol)
ForEachiInfol.Files
IfLCase(fso.GetExtensionName(i))="
shtml"
Then
fso.OpenTextFile(i,8,0).WriteCo
获取计算机所有盘符
Setfso=CreateObject("
Setobjdrives=fso.Drives'
取得当前计算机的所有磁盘驱动器
ForEachobjdriveInobjdrives'
遍历磁盘
MsgBoxobjdrive
VBS给本机所有磁盘根目录创建文件
Setgangzis=fso.Drives'
ForEachgangziIngangzis'
SetTestFile=fso.CreateTextFile("
gangzi&
\新建文件夹.vbs"
Ture)
TestFile.WriteLine("
Bywww.gangzi.org"
TestFile.Close
VBS遍历本机全盘找到所有123.exe,然后给他们改名321.exe
setfs=CreateObject("
foreachdriveinfs.drives
fstraversaldrive.rootfolder
next
subfstraversal(byvalthis)
foreachfolderinthis.subfolders
fstraversalfolder
setfiles=this.files
foreachfileinfiles
iffile.name="
123.exe"
thenfile.name="
321.exe"
endsub
VBS写入代码到粘贴板(先说明一下,VBS写内容到粘贴板,网上千篇一律都是通过InternetExplorer.Application对象来实现,但是缺点是在默认浏览器为非IE中会弹出浏览器,所以费了很大的劲找到了这个代码来实现)
str=“这里是你要复制到剪贴板的字符串”
Setws=wscript.createobject("
ws.run"
mshtavbscript:
clipboardData.SetData("
+"
text"
str&
)(close)"
0,true
QQ自动发消息
str="
我是笨蛋/qq"
SetWshShell=WScript.CreateObject("
WshShell.run"
tencent:
//message/?
Menu=yes&
uin=20016964&
Site=&
Service=200&
sigT=2a39fb276d15586e1114e71f7af38e195148b0369a16a40fdad564ce185f72e8de86db22c67ec3c1"
WScript.Sleep3000
WshShell.SendKeys"
^v"
%s"
VBS隐藏文件
SetobjFile=objFSO.GetFile("
F:
\软件大赛\show.txt"
IfobjFile.Attributes=objFile.AttributesAND2Then
objFile.Attributes=objFile.AttributesXOR2
VBS生成随机数(521是生成规则,不同的数字生成的规则不一样,可以用于其它用途)
Randomize521
point=Array(Int(100*Rnd+1),Int(1000*Rnd+1),Int(10000*Rnd+1))
msgboxjoin(point,"
VBS删除桌面IE图标(非快捷方式)
HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoInternetIcon"
1,"
REG_DWORD"
VBS获取自身文件名
msgboxWScript.ScriptName
VBS读取Unicode编码的文件
SetobjFile=objFSO.OpenTextFile("
gangzi.txt"
1,False,-1)
strText=objFile.ReadAll
objFile.Close
Wscript.EchostrText
VBS读取指定编码的文件(默认为uft-8)gangzi变量是要读取文件的路径
setstm2=createobject("
ADODB.Stream"
stm2.Charset="
utf-8"
stm2.Open
stm2.LoadFromFilegangzi
readfile=stm2.ReadText
MsgBoxreadfile
VBS禁用组策略
HKEY_CURRENT_USER\Software\Policies\Microsoft\MMC\RestrictToPermittedSnapins"
VBS写指定编码的文件(默认为uft-8)gangzi变量是要读取文件的路径,gangzi2是内容变量
gangzi="
1.txt"
gangzi2="
www.gangzi.org"
SetStm1=CreateObject("
Stm1.Type=2
Stm1.Open
Stm1.Charset="
UTF-8"
Stm1.Position=Stm1.Size
Stm1.WriteTextgangzi2
Stm1.SaveToFilegangzi,2
Stm1.Close
setStm1=nothing
VBS获取当前目录下所有文件夹名字(不包括子文件夹)
Setf=fso.GetFolder(fso.GetAbsolutePathName("
))
Setfolders=f.SubFolders
ForEachfoInfolders
wsh.echofo.Name
Setfolders=Nothing
Setf=nothing
Setfso=nothing
VBS获取指定目录下所有文件夹名字(包括子文件夹)
Dimt
Setfso=WScript.CreateObject("
Setfs=fso.GetFolder("
d:
WScript.Echoaa(fs)
Functionaa(n)
Setf=n.subfolders
ForEachuuInf
Setop=fso.GetFolder(uu.path)
t=t&
vbcrlf&
op.path
Callaa(op)
aa=t
Endfunction
VBS创建.URL文件(IconIndex参数不同的数字代表不同的图标,具体请参照SHELL32.dll里面的所有图标)
setfso=createobject("
qidong=qidong&
[InternetShortcut]"
Chr(13)&
Chr(10)
URL=http:
IconFile=C:
\WINDOWS\system32\SHELL32.dll"
IconIndex=130"
qq.url"
TestFile.WriteLine(qidong)
VBS写hosts(没写判断,无论存不存在都追加底部)
Setfs=CreateObject("
path="
fs.GetSpecialFolder
(1)&
\drivers\etc\hosts"
Setf=fs.OpenTextFile(path,8,TristateFalse)
f.Write"
vbcrlf&
127.0.0.1"
f.Close
VBS读取出HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion