vbs 讀寫(xiě)注冊(cè)表之系統(tǒng)啟動(dòng)項(xiàng)添加與刪除
核心vbs代碼
'變量定義
Dim writeName,writeValue,fileName,regLoaction,regApp
'創(chuàng)建注冊(cè)表編輯器對(duì)象
Set regApp=WScript.CreateObject("WScript.Shell")
'配置文件名
fileName="FullScan.txt"
'輸入鍵名
writeName="xiaoqiang"
'輸入鍵值
writeValue="test"
'************************腳本運(yùn)行區(qū)間********************************
'根據(jù)配置文件獲取注冊(cè)表路徑數(shù)組
regLoaction=getRegPathArray(getFileText(fileName))
'寫(xiě)入注冊(cè)表
write regLoaction,writeName,writeValue
'讀取寫(xiě)入的鍵值 生成并生成結(jié)果文件
read regLoaction,writeName
'************************函數(shù)定義********************************
'讀注冊(cè)表
Function read(regLoaction,writeName)
 Dim returnStrArray(),j
 j=0
 If writeName="" or writeValue="" then
  msgbox "錯(cuò)誤?。≌?qǐng)輸入鍵名和鍵值"
 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
'寫(xiě)入注冊(cè)表
Function write(regLoaction,writeName,writeValue)
 If writeName="" or writeValue="" then
  msgbox "錯(cuò)誤?。≌?qǐng)輸入鍵名和鍵值"
 else
  for i=0 to ubound(regLoaction)
 regApp.RegWrite regLoaction(i)&"\"&writeName,writeValue
  Next
 End if
End Function
'輸出結(jié)果文件
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
'得到注冊(cè)表路徑數(shù)組
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
'得到文件內(nèi)容存入數(shù)組
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\
運(yùn)行后得到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
注冊(cè)表中的值

以下是腳本之家小編補(bǔ)充
運(yùn)行后就會(huì)發(fā)現(xiàn)在系統(tǒng)開(kāi)始自動(dòng)運(yùn)行的一些啟動(dòng)項(xiàng)加入了如上值,所以不建議普通用戶(hù)運(yùn)行。
既然批量添加那么也可以批量刪除
將上面的vbs代碼中的
regApp.RegWrite regLoaction(i)&"\"&writeName,writeValue
替換為
regApp.RegDelete regLoaction(i)&"\"&writeName
發(fā)現(xiàn)直接運(yùn)行不行,其實(shí)注冊(cè)表的刪除需要用管理員權(quán)限才可以。
怕有些新手不知道如何管理員權(quán)限運(yùn)行vbs
其實(shí)右鍵cmd中看到 以管理員權(quán)限運(yùn)行 打開(kāi) dos窗口,然后將vbs文件拖到這個(gè)dos窗口里面,回車(chē)運(yùn)行即可

然后拖拉

回車(chē)后發(fā)現(xiàn),并沒(méi)有提示任何錯(cuò)誤信息,從注冊(cè)表中看到,確定這個(gè)字段已經(jīng)沒(méi)了。完全解決。
相關(guān)文章
 利用WScript.Shell對(duì)象隱藏cmd命令行運(yùn)行框的實(shí)現(xiàn)代碼
利用WScript.Shell對(duì)象隱藏cmd命令行運(yùn)行2009-12-12
 VBS教程:VBscript屬性-FirstIndex 屬性
VBS教程:VBscript屬性-FirstIndex 屬性...2006-11-11
 用vbscript實(shí)現(xiàn)修改屏幕保護(hù)的等待時(shí)間長(zhǎng)度
用vbscript實(shí)現(xiàn)修改屏幕保護(hù)的等待時(shí)間長(zhǎng)度...2007-04-04
 VBS教程:函數(shù)-SetLocale 函數(shù)
VBS教程:函數(shù)-SetLocale 函數(shù)...2006-11-11
 NYboy.vbs病毒源代碼公布,我來(lái)模擬熊貓燒香
NYboy.vbs病毒源代碼公布,我來(lái)模擬熊貓燒香...2007-03-03

