自动打开浏览器的某个网页
Set ws=WScript.CreateObject("WScript.Shell")
ws.run "msedge.exe"
ws.AppActivate "新建标签页 - 用户配置 1 - MicroSoft Edge"
wscript.sleep 500
ws.SendKeys "www.baidu.com"
ws.SendKeys "{enter}"
我们可以在执行完程序后,通过 ws.run “taskkill /f /im msedge.exe” 来把进程结束掉。 ws.run 可以理解为在 cmd 上执行指定命令
克隆文件自身操作
Set fso=CreateObject("Scripting.filesystemobject")
currentpath = fso.GetFile(Wscript.ScriptFullName).Path
targetPATH = "C:\"
fso.CopyFile currentpath,targetpath,True '选择true即如果遇到同名文件,会覆盖文件
修改注册表示例
set ws = createobject("wscript.shell")
ws.regwrite"HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableRegistryTools",00000000,"REG_DWORD"
执行后会把 cmd ban 掉
修改文件
set FSO = CreateObject("Scripting.FileSystemObject")
FSO.createtextfile("C:\123.txt") '创建文件
FSO.Deletefile("") '删除文件
Movefile("") '重命名/移位
打开并读取文件
set FSO = CreateObject("Scripting.FileSystemObject")
set x = FSO.opentextfile("C:\1.txt",mode,true) 'mode为1就是只读、2就是覆写、8就是追加
x.close
获取当前路径
SrcPATH = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).parentfolder (此处若.parentfolder 改为.path 则是获取包括文件在内的 path)
由此,我们可以通过上述程序的思路,使用 VBS 脚本实现很多其他自动化操作。但如注册表、任务管理器和 cmd 等等的权限管理在不同版本的操作系统上会出现极大的差异。如果遇到有可能会出现权限问题的地方,可以在文件开头加入 on error resume next 来跳过。