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


核心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=SoftwareMicrosoftWindowsCurrentVersionRun
2=SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorerRun
3=SoftwareMicrosoftWindowsCurrentVersionRunOnce
4=SoftwareMicrosoftWindowsCurrentVersionRunServicesOnce
5=SoftwareMicrosoftWindowsCurrentVersionRunOnceEx
6=SoftwareMicrosoftWindowsCurrentVersionPoliciesSystemShell
7=SoftwareMicrosoftWindowsCurrentVersionShellServiceObjectDelayLoad
8=SoftwarePoliciesMicrosoftWindowsSystemScripts
[HKEY_CURRENT_USER]
1=SoftwareMicrosoftWindowsCurrentVersionRun
2=SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorerRun
3=SoftwareMicrosoftWindowsCurrentVersionRunOnce
4=SoftwareMicrosoftWindowsCurrentVersionRunServicesOnce
5=SoftwareMicrosoftWindowsCurrentVersionRunOnceEx
6=SoftwareMicrosoftWindowsCurrentVersionPoliciesSystemShell
7=SoftwareMicrosoftWindowsCurrentVersionShellServiceObjectDelayLoad
8=SoftwarePoliciesMicrosoftWindowsSystemScripts

�行�得到result.txt

HKLMSoftwareMicrosoftWindowsCurrentVersionRunxiaoqiang? test
HKLMSoftwareMicrosoftWindowsCurrentVersionPoliciesExplorerRun\xiaoqiang? test
HKLMSoftwareMicrosoftWindowsCurrentVersionRunOnce\xiaoqiang? test
HKLMSoftwareMicrosoftWindowsCurrentVersionRunServicesOnce\xiaoqiang? test
HKLMSoftwareMicrosoftWindowsCurrentVersionRunOnceExxiaoqiang? test
HKLMSoftwareMicrosoftWindowsCurrentVersionPoliciesSystemShell\xiaoqiang? test
HKLMSoftwareMicrosoftWindowsCurrentVersionShellServiceObjectDelayLoad\xiaoqiang? test
HKLMSoftwarePoliciesMicrosoftWindowsSystemScripts\xiaoqiang? test
HKCUSoftwareMicrosoftWindowsCurrentVersionRunxiaoqiang? test
HKCUSoftwareMicrosoftWindowsCurrentVersionPoliciesExplorerRun\xiaoqiang? test
HKCUSoftwareMicrosoftWindowsCurrentVersionRunOnce\xiaoqiang? test
HKCUSoftwareMicrosoftWindowsCurrentVersionRunServicesOnce\xiaoqiang? test
HKCUSoftwareMicrosoftWindowsCurrentVersionRunOnceExxiaoqiang? test
HKCUSoftwareMicrosoftWindowsCurrentVersionPoliciesSystemShell\xiaoqiang? test
HKCUSoftwareMicrosoftWindowsCurrentVersionShellServiceObjectDelayLoad\xiaoqiang? test
HKCUSoftwarePoliciesMicrosoftWindowsSystemScripts\xiaoqiang? test

注册表中的�/p>

以下是脚本之家�编补�/strong>

�行�就会�现在系统开始自动�行的一些�动项加入了如上值,所以�建议普通用户�行�/p>

既然批�添加那么也�以批�删�/p>

将上�的vbs代�中的

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

替��/p>

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

�现直接�行�行,其实注册表的删除需�用管�员����以�/p>

怕有些新手�知�如何管�员���行vbs

其实�键cmd中看�以管�员���行 打开 dos窗�,然�将vbs文件拖到这个dos窗�里�,回车�行��/p>

然�拖拉

回车��现,并没有�示任何错误信�,从注册表中看到,确定这个字段已�没了。完全解决�/p>