VBS操作レジストリ16進数

5697 ワード

VBS操作レジストリを使用して、通常はRegRead/RegWrite/RegDelete方法を使用します.
RegRead:
   'read.vbs(       read.vbs  )
   Dim OperationRegistry
   Set OperationRegistry=WScript.CreateObject("WScript.Shell")
   Dim Read_Data1,Read_Data2
   Read_Data1=OperationRegistry.RegRead("HKCR\.xxf\")
   '    HKEY_CLASSES_ROOT   .xxf      ,         Read_Data1
   Read_Data2=OperationRegistry.RegRead("HKCR\.xxf\value")
   '  .xxf     value     ,         Read_Data2
   MsgBox("Default="&Read_Data1&" value="&Read_Data2)
   '          
RegWirte:
'write.vbs
Dim OperationRegistry
Set OperationRegistry=WScript.CreateObject("WScript.Shell")
 Default=OperationRegistry.RegRead("HKCR\")
'       (null)
  
OperationRegistry.RegWrite "HKCR\.xxf\",Default
'   HKEY_CLASSES_ROOT      .xxf,        
  
OperationRegistry.RegWrite "HKCR\.xxf\","xxffile"
'   HKEY_CLASSES_ROOT      .xxf,      ?quot;xxffile"
  
OperationRegistry.RegWrite "HKCR\.xxf\value1","string"
'   .xxf            value1,       "string"
  
OperationRegistry.RegWrite "HKCR\.xxf\value2",1,"REG_DWORD"
'   .xxf      REG_DWORD   value2,       1
  
OperationRegistry.RegWrite "HKCR\.xxf\value3",0Xff,"REG_BINARY"
'   .xxf            value3,            ff
RegDelete:
'delete.vbs

Dim OperationRegistry

Set OperationRegistry=WScript.CreateObject("WScript.Shell")

OperationRegistry.RegRead("HKCR\.xxf\value")

'  .xxf     value  

OperationRegistry.RegRead("HKCR\.xxf\")

'    HKEY_CLASSES_ROOT   .xxf  
 
ただし、16進数のデータを挿入すると問題があります.以下のレジストリキーの値を書き込むと、RegWriteを使用すると、「タイプ不一致」エラーが発生します.RegWirteは16進数の値を書く時、1つの値だけをサポートします.配列はサポートされていません.
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3] 
"{AEBA21FA-782A-4A90-978D-B72164C80120}"=hex:1a,37,61,59,23,52,35,0c,7a,5f,20,\
   17,2f,1e,1a,19,0e,2b,01,73,13,37,13,12,14,1a,15,2a,4e,2c,08,0d,20,1b,28,18,\
   36,32 
 RegWrite方式を使う
Dim OperationRegistry  
Set OperationRegistry=WScript.CreateObject("WScript.Shell")  
OperationRegistry.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3","0xff,0x11","REG_BINARY"
 
エラーは以下の通りです
---------------------------
Windows Script Host
---------------------------
  :	C:\Work\Documents\BOC\BOC.Bancslink\VBS\ie_config\ie_forie -   .vbs
 :	3
  :	1
  :	     
  :	800A000D
 : 	Microsoft VBScript      

---------------------------
     
---------------------------
 
 解決方法:
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."

Set objRegistry = GetObject _
    ("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3"
strValueName = "{1EBA21FA-782A-4A90-978D-B72164C80120}"
arrValues = Split("1a,37,61,59,23,52,35,0c,7a,5f,20,17,2f,1e,1a,19,0e,2b,01,73,13,37,13,12,14,1a,15,39,4e,2c,08,0d,20,1b,28,18,36,32", ",")
For i = 0 To UBound(arrValues) : arrValues(i) = CByte("&H" & arrValues(i)) : Next

errReturn = objRegistry.SetBinaryValue _
    (HKEY_CURRENT_USER, strKeyPath, strValueName, arrValues)
 
参考:
http://www.cnblogs.com/heimirror/archive/2008/06/25/1229483.html
https://msdn.microsoft.com/de-de/library/aa393286%28v=vs.85%29.aspx
http://stackoverflow.com/questions/26967459/convert-hex-string-into-array-and-write-it-to-registry-vbscript