vbs 读写注册表之系统启动项添加与删除(vb读写注册表)速看

随心笔谈2年前发布 admin
201 0 0

文章摘要

该脚本是一个使用VBScript编写的注册表操作工具,主要用于从配置文件中读取注册表路径,并在其上写入键值,最后将结果保存到result.txt文件中。其主要功能包括: 1. **读取配置文件**:从指定的*.txt文件中获取注册表路径信息。 2. **解析注册表路径**:根据配置文件内容解析出具体的注册表路径,并生成可操作的路径数组。 3. **写入注册表**:通过写入键值到注册表路径,实现对注册表的批量修改。 4. **生成结果文件**:将写入后的注册表内容保存到result.txt文件中。 该脚本适用于需要对注册表进行批量操作的场景,能够高效地处理和存储注册表数据。


‘变量定义
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&”? “®App.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

© 版权声明

相关文章