vbs读写注册表之系统启动项添加与删除的示例分析

这篇文章主要介绍了vbs读写注册表之系统启动项添加与删除的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

核心vbs代码

'变量定义
DimwriteName,writeValue,fileName,regLoaction,regApp

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

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

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

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

'写入注册表
writeregLoaction,writeName,writeValue

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

'************************函数定义********************************
'读注册表
Functionread(regLoaction,writeName)
DimreturnStrArray(),j
j=0
IfwriteName=""orwriteValue=""then
msgbox"错误!!请输入键名和键值"
else
fori=0toubound(regLoaction)
ReDimPreservereturnStrArray(j)
regPath=regLoaction(i)&"\"&writeName
returnStrArray(j)=regPath&"?"&regApp.RegRead(regPath)
j=j+1
Next
Endif
writeResultreturnStrArray
EndFunction

'写入注册表
Functionwrite(regLoaction,writeName,writeValue)
IfwriteName=""orwriteValue=""then
msgbox"错误!!请输入键名和键值"
else
fori=0toubound(regLoaction)
regApp.RegWriteregLoaction(i)&"\"&writeName,writeValue
Next
Endif
EndFunction

'输出结果文件
subwriteResult(contentArray)
ConstForReading=1,ForWriting=2
Dimfso,f,returnStrArray(),i
Setfso=CreateObject("Scripting.FileSystemObject")
Setf=fso.OpenTextFile("result.txt",2,true)
fori=0toubound(contentArray)
f.writeline(contentArray(i))
Next
f.close()
EndSub

'得到注册表路径数组
FunctiongetRegPathArray(sourceArray)
Dimhead,returnStrArray(),j
j=0
fori=0toubound(sourceArray)
IfsourceArray(i)="[HKEY_LOCAL_MACHINE]"then
head="HKLM"
elseifsourceArray(i)="[HKEY_USERS]"then
head="HKEY_USERS\.DEFAULT"
elseifsourceArray(i)="[HKEY_CURRENT_USER]"then
head="HKCU"
elseifsourceArray(i)="[HKEY_CLASSES_ROOT]"then
head="HKCR"
elseifsourceArray(i)="[HKEY_CURRENT_CONFIG]"then
head="HKEY_CURRENT_CONFIG"
else
ReDimPreservereturnStrArray(j)
str=head&split(sourceArray(i),"=")(1)
returnStrArray(j)=str
j=j+1
EndIf
Next
getRegPathArray=returnStrArray
EndFunction

'得到文件内容存入数组
FunctiongetFileText(fileName)
ConstForReading=1,ForWriting=2
Dimfso,f,returnStrArray(),i
Setfso=CreateObject("Scripting.FileSystemObject")
Setf=fso.OpenTextFile(fileName,1)
i=0
dowhilef.atendofstream<>true
ReDimPreservereturnStrArray(i)
returnStrArray(i)=f.readline()
i=i+1
loop
f.close()
getFileText=returnStrArray
EndFunction

//配置文件

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读写注册表之系统启动项添加与删除的示例分析

以下是恰卡编程网小编补充

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

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

将上面的vbs代码中的

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

替换为

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

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

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

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

vbs读写注册表之系统启动项添加与删除的示例分析

然后拖拉

vbs读写注册表之系统启动项添加与删除的示例分析

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

感谢你能够认真阅读完这篇文章,希望小编分享的“vbs读写注册表之系统启动项添加与删除的示例分析”这篇文章对大家有帮助,同时也希望大家多多支持恰卡编程网,关注恰卡编程网行业资讯频道,更多相关知识等着你来学习!

发布于 2021-07-24 22:37:52
收藏
分享
海报
0 条评论
180
上一篇:Ubuntu 12.04 x64怎么安装nagios 下一篇:ASP.NET Core环境变量和启动设置的示例分析
目录

    推荐阅读

    0 条评论

    本站已关闭游客评论,请登录或者注册后再评论吧~

    忘记密码?

    图形验证码