vbs 读写注册表之系统启动项添加与删除

所属分类: 脚本专栏 / vbs 阅读数: 1952
收藏 0 赞 0 分享

核心vbs代码

'变量定义
Dim writeName,writeValue,fileName,regLoaction,regApp

'创建注册表编辑器对象
Set regApp=WScript.CreateObject("WScript.Shell")

'配置文件名
fileName="FullScan.txt"
'输入键名
writeName="xiaoqiang"
'输入键值
writeValue="test"

'************************脚本运行区间********************************

'根据配置文件获取注册表路径数组
regLoaction=getRegPathArray(getFileText(fileName))

'写入注册表
write regLoaction,writeName,writeValue

'读取写入的键值 生成并生成结果文件
read regLoaction,writeName

'************************函数定义********************************
'读注册表
Function read(regLoaction,writeName)
 Dim returnStrArray(),j
 j=0
 If writeName="" or writeValue="" then
  msgbox "错误!!请输入键名和键值"
 else
  for i=0 to ubound(regLoaction)
 ReDim Preserve returnStrArray(j) 
   regPath=regLoaction(i)&"\"&writeName
   returnStrArray(j)=regPath&"? "&regApp.RegRead(regPath)
   j=j+1
  Next
 End if
 writeResult returnStrArray
End Function

'写入注册表
Function write(regLoaction,writeName,writeValue)
 If writeName="" or writeValue="" then
  msgbox "错误!!请输入键名和键值"
 else
  for i=0 to ubound(regLoaction)
 regApp.RegWrite regLoaction(i)&"\"&writeName,writeValue
  Next
 End if
End Function

'输出结果文件
sub writeResult(contentArray)
 Const ForReading = 1, ForWriting = 2
 Dim fso,f,returnStrArray(),i
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set f = fso.OpenTextFile("result.txt", 2,true)
 for i=0 to ubound(contentArray)
 f.writeline(contentArray(i))
 Next
 f.close()
End Sub

'得到注册表路径数组
Function getRegPathArray(sourceArray)
 Dim head,returnStrArray(),j
 j=0
 for i=0 to ubound(sourceArray)
  If sourceArray(i)="[HKEY_LOCAL_MACHINE]" then
 head="HKLM"
  elseif sourceArray(i)="[HKEY_USERS]" then
   head="HKEY_USERS\.DEFAULT"
  elseif sourceArray(i)="[HKEY_CURRENT_USER]" then
   head="HKCU"
  elseif sourceArray(i)="[HKEY_CLASSES_ROOT]" then
   head="HKCR"
  elseif sourceArray(i)="[HKEY_CURRENT_CONFIG]" then
   head="HKEY_CURRENT_CONFIG"
  else
   ReDim Preserve returnStrArray(j)
   str=head&split(sourceArray(i),"=")(1)
   returnStrArray(j)=str
   j=j+1
  End If
 Next
 getRegPathArray=returnStrArray
End Function

'得到文件内容存入数组
Function getFileText(fileName)
 Const ForReading = 1, ForWriting = 2
 Dim fso,f,returnStrArray(),i
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set f = fso.OpenTextFile(fileName, 1)
 i=0
 do while f.atendofstream<>true
  ReDim Preserve returnStrArray(i)
  returnStrArray(i)=f.readline()
  i=i+1
 loop
 f.close()
 getFileText=returnStrArray
End Function

//配置文件

FullScan.txt

[HKEY_LOCAL_MACHINE]
1=\Software\Microsoft\Windows\CurrentVersion\Run
2=\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run\
3=\Software\Microsoft\Windows\CurrentVersion\RunOnce\
4=\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce\
5=\Software\Microsoft\Windows\CurrentVersion\RunOnceEx
6=\Software\Microsoft\Windows\CurrentVersion\Policies\System\Shell\
7=\Software\Microsoft\Windows\CurrentVersion\ShellServiceObjectDelayLoad\
8=\Software\Policies\Microsoft\Windows\System\Scripts\
[HKEY_CURRENT_USER]
1=\Software\Microsoft\Windows\CurrentVersion\Run
2=\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run\
3=\Software\Microsoft\Windows\CurrentVersion\RunOnce\
4=\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce\
5=\Software\Microsoft\Windows\CurrentVersion\RunOnceEx
6=\Software\Microsoft\Windows\CurrentVersion\Policies\System\Shell\
7=\Software\Microsoft\Windows\CurrentVersion\ShellServiceObjectDelayLoad\
8=\Software\Policies\Microsoft\Windows\System\Scripts\

运行后得到result.txt

HKLM\Software\Microsoft\Windows\CurrentVersion\Run\xiaoqiang? test
HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run\\xiaoqiang? test
HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce\\xiaoqiang? test
HKLM\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce\\xiaoqiang? test
HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnceEx\xiaoqiang? test
HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\Shell\\xiaoqiang? test
HKLM\Software\Microsoft\Windows\CurrentVersion\ShellServiceObjectDelayLoad\\xiaoqiang? test
HKLM\Software\Policies\Microsoft\Windows\System\Scripts\\xiaoqiang? test
HKCU\Software\Microsoft\Windows\CurrentVersion\Run\xiaoqiang? test
HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run\\xiaoqiang? test
HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce\\xiaoqiang? test
HKCU\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce\\xiaoqiang? test
HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnceEx\xiaoqiang? test
HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\Shell\\xiaoqiang? test
HKCU\Software\Microsoft\Windows\CurrentVersion\ShellServiceObjectDelayLoad\\xiaoqiang? test
HKCU\Software\Policies\Microsoft\Windows\System\Scripts\\xiaoqiang? test

注册表中的值

以下是脚本之家小编补充

运行后就会发现在系统开始自动运行的一些启动项加入了如上值,所以不建议普通用户运行。

既然批量添加那么也可以批量删除

将上面的vbs代码中的

regApp.RegWrite regLoaction(i)&"\"&writeName,writeValue

替换为

regApp.RegDelete regLoaction(i)&"\"&writeName

发现直接运行不行,其实注册表的删除需要用管理员权限才可以。

怕有些新手不知道如何管理员权限运行vbs

其实右键cmd中看到 以管理员权限运行 打开 dos窗口,然后将vbs文件拖到这个dos窗口里面,回车运行即可

然后拖拉

回车后发现,并没有提示任何错误信息,从注册表中看到,确定这个字段已经没了。完全解决。

更多精彩内容其他人还在看

用vbscript来添加ip策略 自动封IP

看过有网友介绍的方法,不过是手工一条一条地封,而攻击IP一般都是数千个不同的IP。用手工封IP的办法太麻烦。下面我们用程序来实现自动封这些IP!
收藏 0 赞 0 分享

vbs,hta中选择文件夹对话框实现代码

在vbs中选择文件夹可以直接调用系统的文件夹对话框
收藏 0 赞 0 分享

WMI 脚本高手不完全手册

要成为WMI脚本高手当要认识一下什么叫WMI啦,下面将介绍一下有关WMI的东西。
收藏 0 赞 0 分享

vbscript语句中“&amp;H”专用于16进制数表示

近段时间在做一个asp的项目,由于数据库里面的字段采用字母“h”开头,在sql语言时就出现了莫名其妙的错误,经过反复的检查,也没查出有错误的地方,整整给折腾了我一天的时间。
收藏 0 赞 0 分享

URL 筛选小工具 提取网页中的超链接地址

这个VBS是用来将一个本地网页中的URL筛选出来并保存在新的网页文件中。当然,只要改变里面的正则表达式,就可以作其他用途了。
收藏 0 赞 0 分享

VBScript 文件操作代码小结

下面是一些vbs下常用到的一些文件操作代码,整理了下方便以后开发使用,提高效率。
收藏 0 赞 0 分享

vbs 错误捕获器,用于捕获内部错误并进行手工处理

vbs中的错误捕获器,用于捕获内部错误并进行手工处理
收藏 0 赞 0 分享

查看SQL状态的vbs(检验SQL SERVER是否在这机器上工作 )

这篇文章主要介绍了查看SQL状态的vbs,主要检验SQL SERVER是否在这机器上工作,需要的朋友可以参考下
收藏 0 赞 0 分享

vbs 字符统计功能模块

TongJi()将上面代码保存为TongJi.vbs,在TongJi.vbs同目录下建立ok.txt文本文件,将你要统计的文本复制到ok.txt中,运行TongJi.vbs即可以统计字数,与word的功能一样。
收藏 0 赞 0 分享

重新安装ie的一个vbs

对于版本有点老,所以建议学习使用,不要随便直接运行。
收藏 0 赞 0 分享
查看更多