网管联盟论坛 - 共享互助,专助进取

 找回密码
 立即注册

QQ登录

只需一步,快速开始

DBNT云维护 三层集中管理 手机远程深蓝软件微信公众号深蓝防逃费V6(多收费共存/全自动处理)
查看: 116|回复: 1

[vb,vbs] VBS脚本常用经典代码

[复制链接]

14

主题

25

帖子

33

积分

初出茅庐(02级)

Rank: 2

发表于 2019-2-25 17:02:07 | 显示全部楼层 |阅读模式

1、VBS获取系统安装路径

/*先定义这个变量是获取系统安装路径的,然后我们用“&strWinDir&”调用这个变量。*/

setWshShell = WScript.CreateObject("WScript.Shell")

strWinDir= WshShell.ExpandEnvironmentStrings("%WinDir%")

2、VBS获取C:/Program Files路径

msgbox  CreateObject("WScript.Shell").ExpandEnvironmentStrings("%ProgramFiles%")

3、VBS获取C:/Program Files/Common Files路径

msgboxCreateObject("WScript.Shell").ExpandEnvironmentStrings("%CommonProgramFiles%")

4、给桌面添加网址快捷方式

setgangzi = WScript.CreateObject("WScript.Shell")

strDesktop= gangzi.SpecialFolders("Desktop")

setoShellLink = gangzi.CreateShortcut(strDesktop & "/InternetExplorer.lnk")

oShellLink.TargetPath= "http://www.fendou.info"

oShellLink.Description= "Internet Explorer"

oShellLink.IconLocation= "%ProgramFiles%/Internet Explorer/iexplore.exe, 0"

oShellLink.Save

5、给收藏夹添加网址

ConstADMINISTRATIVE_TOOLS = 6

SetobjShell = CreateObject("Shell.Application")

SetobjFolder = objShell.Namespace(ADMINISTRATIVE_TOOLS)

SetobjFolderItem = objFolder.Self   

SetobjShell = WScript.CreateObject("WScript.Shell")

strDesktopFld= objFolderItem.Path

SetobjURLShortcut = objShell.CreateShortcut(strDesktopFld & "/奋斗Blog.url")

objURLShortcut.TargetPath= "http://www.fendou.info/"

objURLShortcut.Save

6、删除指定目录指定后缀文件

OnError Resume Next

Setfso = CreateObject("Scripting.FileSystemObject")

fso.DeleteFile"C:/*.vbs", True

Setfso = Nothing

7、VBS改主页

SetoShell = CreateObject("WScript.Shell")

oShell.RegWrite  "HKEY_CURRENT_USER/Software/Microsoft/InternetExplorer/Main/Start Page","http://www.fendou.info"

8、VBS加启动项

SetoShell=CreateObject("Wscript.Shell")

oShell.RegWrite"HKLM/Software/Microsoft/Windows/CurrentVersion/Run/cmd","cmd.exe"

9、VBS复制自己

setcopy1=createobject("scripting.filesystemobject")

copy1.getfile(wscript.scriptfullname).copy("c:/huan.vbs")

setcopy1=createobject("scripting.filesystemobject")

copy1.getfile("game.exe").copy("c:/gangzi.exe")

/*复制自己到C盘的huan.vbs(复制本vbs目录下的game.exe文件到c盘的gangzi.exe)*/

10、就算代码出错 依然继续执行

OnError Resume Next

11、VBS打开网址

SetobjShell = CreateObject("Wscript.Shell")

objShell.Run("http://www.fendou.info/")

12、VBS获取网卡MAC地址

Dimmc,mo

Setmc=GetObject("Winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")

ForEach mo In mc

Ifmo.IPEnabled=True Then

MsgBox"本机网卡MAC地址是: " & mo.MacAddress

ExitFor

EndIf

Next

13、VBS获取本机注册表主页地址

Setreg=WScript.CreateObject("WScript.Shell")

startpage=reg.RegRead("HKEY_CURRENT_USER/Software/Microsoft/InternetExplorer/Main/Start Page")

MsgBoxstartpage

14、VBS遍历本机全盘找到所有123.exe,然后给他们改名321.exe

setfs = CreateObject("Scripting.FileSystemObject")

foreach drive in fs.drives

fstraversaldrive.rootfolder

next

subfstraversal(byval this)

foreach folder in this.subfolders

fstraversalfolder

next

setfiles = this.files

foreach file in files

iffile.name = "123.exe" then file.name = "321.exe"

next

endsub

15、VBS删除桌面IE图标(非快捷方式)

SetoShell = CreateObject("WScript.Shell")

oShell.RegWrite"HKCU/Software/Microsoft/Windows/CurrentVersion/Policies/Explorer/NoInternetIcon",1,"REG_DWORD"

16、VBS禁用组策略

SetoShell = CreateObject("WScript.Shell")

oShell.RegWrite"HKEY_CURRENT_USER/Software/Policies/Microsoft/MMC/RestrictToPermittedSnapins",1,"REG_DWORD"

17、VBS运行后删除自身代码

dimfso,f

Setfso = CreateObject("Scripting.FileSystemObject")

f= fso.DeleteFile(WScript.ScriptName)

WScript.Echo(WScript.ScriptName)


评分

参与人数 1金币 +3 牛人值 +3 收起 理由
扫地生 + 3 + 3 赞一个!

查看全部评分

回复

使用道具 举报

54

主题

91

帖子

143

积分

DBNT团队技术支持

Rank: 21Rank: 21Rank: 21Rank: 21Rank: 21Rank: 21

发表于 2019-2-26 12:04:39 | 显示全部楼层
很好的分享。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

联盟首页|软件下载|联系我们|手机版|小黑屋|纯文字版|网管联盟 ( 粤ICP备17103197号-2 )

GMT+8, 2019-3-22 21:11 , Processed in 0.148456 second(s), 25 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表