VBS写入代码到粘贴板(先说明一下,VBS写内容到粘贴板,网上千篇一律都是通过InternetExplorer.Application对象来实现,但是缺点是在默认浏览器为非IE中会弹出浏览器,所以费了很大的劲找到了这个代码来实现)- str=“这里是你要复制到剪贴板的字符串”
- Set ws = wscript.createobject("wscript.shell")
- ws.run "mshta vbscript:clipboardData.SetData("+""""+"text"+""""+","+""""&str&""""+")(close)",0,true
复制代码 QQ自动发消息- On Error Resume Next
- str="我是笨蛋/qq"
- Set WshShell=WScript.CreateObject("WScript.Shell")
- WshShell.run "mshta vbscript:clipboardData.SetData("+""""+"text"+""""+","+""""&str&""""+")(close)",0
- WshShell.run "tencent://message/?Menu=yes&uin=20016964&Site=&Service=200&sigT=2a39fb276d15586e1114e71f7af38e195148b0369a16a40fdad564ce185f72e8de86db22c67ec3c1",0,true
- WScript.Sleep 3000
- WshShell.SendKeys "^v"
- WshShell.SendKeys "%s"
复制代码 VBS隐藏文件- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objFile = objFSO.GetFile("F:\软件大赛\show.txt")
- If objFile.Attributes = objFile.Attributes AND 2 Then
- objFile.Attributes = objFile.Attributes XOR 2
- End If
复制代码 VBS生成随机数(521是生成规则,不同的数字生成的规则不一样,可以用于其它用途)- Randomize 521
- point=Array(Int(100*Rnd+1),Int(1000*Rnd+1),Int(10000*Rnd+1))
- msgbox join(point,"")
复制代码 VBS删除桌面IE图标(非快捷方式)- Set oShell = CreateObject("WScript.Shell")
- oShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoInternetIcon",1,"REG_DWORD"
复制代码 VBS获取自身文件名- Set fso = CreateObject("Scripting.FileSystemObject")
- msgbox WScript.ScriptName
复制代码 VBS读取Unicode编码的文件- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objFile = objFSO.OpenTextFile("gangzi.txt",1,False,-1)
- strText = objFile.ReadAll
- objFile.Close
- Wscript.Echo strText
复制代码 VBS读取指定编码的文件(默认为uft-8)gangzi变量是要读取文件的路径- set stm2 =createobject("ADODB.Stream")
- stm2.Charset = "utf-8"
- stm2.Open
- stm2.LoadFromFile gangzi
- readfile = stm2.ReadText
- MsgBox readfile
复制代码 VBS禁用组策略- Set oShell = CreateObject("WScript.Shell")
- oShell.RegWrite "HKEY_CURRENT_USER\Software\Policies\Microsoft\MMC\RestrictToPermittedSnapins",1,"REG_DWORD"
复制代码 VBS写指定编码的文件(默认为uft-8)gangzi变量是要读取文件的路径,gangzi2是内容变量- gangzi="1.txt"
- gangzi2="www.gangzi.org"
- Set Stm1 = CreateObject("ADODB.Stream")
- Stm1.Type = 2
- Stm1.Open
- Stm1.Charset = "UTF-8"
- Stm1.Position = Stm1.Size
- Stm1.WriteText gangzi2
- Stm1.SaveToFile gangzi,2
- Stm1.Close
- set Stm1 = nothing
复制代码 VBS获取当前目录下所有文件夹名字(不包括子文件夹)- Set fso=CreateObject("scripting.filesystemobject")
- Set f=fso.GetFolder(fso.GetAbsolutePathName("."))
- Set folders=f.SubFolders
- For Each fo In folders
- wsh.echo fo.Name
- Next
- Set folders=Nothing
- Set f=nothing
- Set fso=nothing
复制代码 VBS获取指定目录下所有文件夹名字(包括子文件夹)- Dim t
- Set fso=WScript.CreateObject("scripting.filesystemobject")
- Set fs=fso.GetFolder("d:\")
- WScript.Echo aa(fs)
- Function aa(n)
- Set f=n.subfolders
- For Each uu In f
- Set op=fso.GetFolder(uu.path)
- t=t & vbcrlf & op.path
- Call aa(op)
- Next
- aa=t
- End function
复制代码 VBS创建.URL文件(IconIndex参数不同的数字代表不同的图标,具体请参照SHELL32.dll里面的所有图标)- set fso=createobject("scripting.filesystemobject")
- qidong=qidong&"[InternetShortcut]"&Chr(13)&Chr(10)
- qidong=qidong&"URL=http://www.fendou.info"&Chr(13)&Chr(10)
- qidong=qidong&"IconFile=C:\WINDOWS\system32\SHELL32.dll"&Chr(13)&Chr(10)
- qidong=qidong&"IconIndex=130"&Chr(13)&Chr(10)
- Set TestFile=fso.CreateTextFile("qq.url",Ture)
- TestFile.WriteLine(qidong)
- TestFile.Close
复制代码 VBS写hosts(没写判断,无论存不存在都追加底部)- Set fs = CreateObject("Scripting.FileSystemObject")
- path = ""&fs.GetSpecialFolder(1)&"\drivers\etc\hosts"
- Set f = fs.OpenTextFile(path,8,TristateFalse)
- f.Write ""&vbcrlf&"127.0.0.1 www.g.cn"&vbcrlf&"127.0.0.1 g.cn"
- f.Close
复制代码 VBS读取出HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace 下面所有键的名字并循环输出- Const HKLM = &H80000002
- strPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace"
- Set oreg = GetObject("Winmgmts:\root\default:StdRegProv")
- oreg.EnumKey HKLM,strPath,arr
- For Each x In arr
- WScript.Echo x
- Next
复制代码 VBS创建txt文件- Dim fso,TestFile
- Set fso=CreateObject("Scripting.FileSystemObject")
- Set TestFile=fso.CreateTextFile("C:\hello.txt",Ture)
- TestFile.WriteLine("Hello,World!")
- TestFile.Close
复制代码 VBS创建文件夹- Dim fso,fld
- Set fso=CreateObject("Scripting.FileSystemObject")
- Set fld=fso.CreateFolder("C:\newFolder")
复制代码 VBS判断文件夹是否存在- Dim fso,fld
- Set fso=CreateObject("Scripting.FileSystemObject")
- If (fso.FolderExists("C:\newFolder")) Then
- msgbox("Folder exists.")
- else
- set fld=fso.CreateFolder("C:\newFolder")
- End If
复制代码 VBS使用变量判断文件夹- Dim fso,fld
- drvName="C:\"
- fldName="newFolder"
- Set fso=CreateObject("Scripting.FileSystemObject")
- If (fso.FolderExists(drvName&fldName)) Then
- msgbox("Folder exists.")
- else
- set fld=fso.CreateFolder(drvName&fldName)
- End If
复制代码
|