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

 

 

//配置文件

QuickScan.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\

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章