脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - VBS - vbs 读写注册表之系统启动项添加与删除

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

2020-08-20 10:45VBS教程网 VBS

这篇文章主要介绍了vbs 读写注册表之系统启动项添加值,需要的朋友可以参考下

核心vbs代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'变量定义
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 读写注册表之系统启动项添加与删除

以下是服务器之家小编补充

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

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

将上面的vbs代码中的

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

替换为

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

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

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

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

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

然后拖拉

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

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

延伸 · 阅读

精彩推荐
  • VBS雷客图ASP站长安全助手vbs测试版代码

    雷客图ASP站长安全助手vbs测试版代码

    雷客图ASP站长安全助手是一个基于ASP的帮助站长维护网站安全的程序。这个版本(vbs测试版)主要用于服务器本地运行以查找ASP木马。此版本为测试版,希...

    脚本之家2312020-07-03
  • VBSVBS数组深入浅出

    VBS数组深入浅出

    VBS数组在应用中没有像其他语句那么广泛,VBS数组存在不少功能上的局限性(如二维数组的定义、赋值),在使用上也没有java等语言那么便捷...

    VBS教程网2962020-08-18
  • VBSVBS文本文件操作实现代码

    VBS文本文件操作实现代码

    这篇文章主要介绍了VBS文本文件操作实现代码,需要的朋友可以参考下...

    VBS代码网8912020-08-12
  • VBSWINDOWS脚本实践:为SAP补丁制作的VBS脚本代码

    WINDOWS脚本实践:为SAP补丁制作的VBS脚本代码

    本文主要分享WINDOWS脚本实践:为SAP补丁制作的VBS脚本代码,有需要的童鞋可以参考下...

    脚本之家3232020-07-06
  • VBS灵活实用VBS入门教程应用篇

    灵活实用VBS入门教程应用篇

    上一篇文章我们了解了VBS编程的一些基础知识,要更深入地学习还要学习选择结构和循环结构。 ...

    VBS教程网5742020-07-01
  • VBSAdsutil.vbs 在脚本攻击中的妙用[我非我原创]

    Adsutil.vbs 在脚本攻击中的妙用[我非我原创]

    adsutil.vbs是什么?相信用过IIS的网管员不会不知道。这是IIS自带的提供于命令行下管理IIS的一个脚本。位于%SystemDrive%\Inetpub\AdminScripts目录下。...

    VBS教程网2312020-07-07
  • VBSVBS教程:正则表达式简介 -正则表达式语法

    VBS教程:正则表达式简介 -正则表达式语法

    正则表达式语法 一个正则表达式就是由普通字符(例如字符 a 到 z)以及特殊字符(称为元字符)组成的文字模式。该模式描述在查找文字主体时待匹配的...

    VBS教程网3302019-11-25
  • VBSVBS编程教程 (第1篇)

    VBS编程教程 (第1篇)

    VBScript的全称是:Microsoft Visual Basic Script Editon.(微软公司可视化BASIC脚本版). 正如其字面所透露的信息, VBS(VBScript的进一步简写)是基于Visual Basic的脚本语言....

    VBS教程网4812020-07-15