/build/static/layout/Breadcrumb_cap_w.png

VBS - Writing in HKU registry.

Hello, All.

Any idea on how to write a value  of REG_BINARY data type using VBS?

HKU\.Default\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections

 

Following the links you provide here's my code. I think there's something wrong because it can't write the registry

 Option Explicit

Dim uBinary, strPath, runReturn, objWMIReg
Const HKEY_USERS = &H8000003

Set objWMIReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

'Hexa Value to write
'(3c,00,00,00,03,00,00,00,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00)

strPath = ".DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"

'Converted to hexa to decimal
uBinary = Array (60,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)

runReturn = objWMIReg.SetBinaryValue(HKEY_USERS, strPath, "DefaultConnectionSettings", uBinary)

If (runReturn = 0) then
	msgbox "Successful"
Else
	msgbox "Failed"
End if

Set objWMIReg = Nothing

0 Comments   [ + ] Show comments

Answers (4)

Answer Summary:
regWriteBinary "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", "DefaultConnectionSettings", "60,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" Sub regWriteBinary(sRegKey, sRegValue, sBinaryData) ' Expects sBinaryData to be a comma separated string of hex values ' sRegKey needs to start with full registry root, e.g. HKEY_CURRENT_USER and not VBScript short form HKCU Dim oShell, oFSO, oFile, oExec Dim sTempFile Set oShell = CreateObject("WScript.Shell") Set oFSO = CreateObject("Scripting.FileSystemObject") sTempFile = oShell.ExpandEnvironmentStrings("%temp%\RegWriteBinary.reg") Set oFile = oFSO.CreateTextFile(sTempFile,True) oFile.WriteLine("Windows Registry Editor Version 5.00") oFile.WriteLine("") oFile.WriteLine("[" & sRegKey & "]") oFile.WriteLine(Chr(34) & sRegValue & Chr(34) & "=" & "hex:" & sBinaryData) oFile.Close Set oExec = oShell.Exec("reg.exe import """ & sTempFile & """") If InStr(1,oExec.StdErr.ReadAll,"operation completed successfully",vbTextCompare) Then ' Yes the success text IS sent out via StdErr and NOT StdOut WScript.Echo "Registry updated sucessfully" oFSO.DeleteFile sTempFile Else WScript.Echo "regWriteBinary: Registry import of " & sTempFile & " failed: " & oExec.StdErr.ReadAll End If End Sub
Posted by: jagadeish 11 years ago
Red Belt
3

The below VBScript code should work

 

regWriteBinary "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", "DefaultConnectionSettings", "60,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"

Sub regWriteBinary(sRegKey, sRegValue, sBinaryData)
      ' Expects sBinaryData to be a comma separated string of hex values
      ' sRegKey needs to start with full registry root, e.g. HKEY_CURRENT_USER and not VBScript short form HKCU
      Dim oShell, oFSO, oFile, oExec
      Dim sTempFile
      Set oShell = CreateObject("WScript.Shell")
      Set oFSO = CreateObject("Scripting.FileSystemObject")
      sTempFile = oShell.ExpandEnvironmentStrings("%temp%\RegWriteBinary.reg")
      Set oFile = oFSO.CreateTextFile(sTempFile,True)
      oFile.WriteLine("Windows Registry Editor Version 5.00")
      oFile.WriteLine("")
      oFile.WriteLine("[" & sRegKey & "]")
      oFile.WriteLine(Chr(34) & sRegValue & Chr(34) & "=" & "hex:" & sBinaryData)
      oFile.Close
      Set oExec = oShell.Exec("reg.exe import """ & sTempFile & """")
      If InStr(1,oExec.StdErr.ReadAll,"operation completed successfully",vbTextCompare) Then
             ' Yes the success text IS sent out via StdErr and NOT StdOut
             WScript.Echo "Registry updated sucessfully"
             oFSO.DeleteFile sTempFile
      Else
             WScript.Echo "regWriteBinary: Registry import of " & sTempFile & " failed: " & oExec.StdErr.ReadAll
      End If
End Sub


 


Comments:
  • Yes. I tried this one thank you. - ajcbasilio 11 years ago
Posted by: jagadeish 11 years ago
Red Belt
2

Comments:
  • Would you mind to check? I updated my question. - ajcbasilio 11 years ago
Posted by: RaSko 11 years ago
Purple Belt
1

Comments:
  • Can you check? I updated my question. - ajcbasilio 11 years ago
Posted by: SMal.tmcc 11 years ago
Red Belt
0

http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/a-simple-way-to-write-to-the-registry-with-vbscript/


Comments:
  • Would you mind to check? I updated my question. - ajcbasilio 11 years ago
    • you may want to approach it this way also
      http://www.itninja.com/blog/view/how-to-make-changes-to-the-default-users-hive-as-a-post-taks - SMal.tmcc 11 years ago
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ