Link to home
Start Free TrialLog in
Avatar of mcpp661
mcpp661

asked on

VBscript to edit binary registry values

I've been given some VBscript code that uses a reg file for input and it works under my account but it will not work for regular users because group policies are in place that prevent users from accessing regedit. Here's the code that I'm speaking of:

Option Explicit
On error resume next
dim objShell

set objShell = CreateObject("Wscript.Shell")

objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\PrivacyAdvanced",1,"REG_DWORD"
objShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\New Windows\PopupMgr",0,"REG_DWORD"
objShell.Run "regedit /s ""<REG_File_Path>", 1, False

Set objShell = Nothing

WScript.quit

I'm going to have to abandon that line that calls regedit and have VBscript directly edit a couple of binary registry values. Below are the values that need to be edited (taken directly from a .reg file). How can I edit these binary values using the RegWrite method, or is some other means necessary to edit binary values?

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

"{A8A88C49-5EB2-4990-A1A2-0876022C854F}"=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
Avatar of Raquero
Raquero
Flag of United States of America image

Since you mention Group Policy, this is much easier to do using Group Policy Preferences in a GPO.

http://technet.microsoft.com/en-us/library/cc753092.aspx
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=24449


With XP clients you will need the client side extension to use GPP: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=3628

Create and edit the GPO from a 2003 R2 or later server.
Here is a script i have done for you this should do it

Option Explicit
Dim objShell
Set objShell = CreateObject("WScript.Shell")

'Add StdRegProv support in case of Binary, Multi_SZ values
Dim strComputer, ArrOfValue, oReg
const HKEY_USERS = &H80000003
const HKEY_LOCAL_MACHINE = &H80000002
const HKEY_CURRENT_USER = &H80000001
const HKEY_CLASSES_ROOT = &H80000000
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")	'used for Binary, Multi_SZ values
objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\", ""
ArrOfValue = Array(&H1a,&H37,&H61,&H59,&H23,&H52,&H35,&H0c,&H7a,&H5f,&H20,_	'Building array for handling BINARY Value
&H17,&H2f,&H1e,&H1a,&H19,&H0e,&H2b,&H01,&H73,&H13,&H37,&H13,&H12,&H14,&H1a,&H15,&H2a,&H4e,&H2c,&H08,&H0d,&H20,&H1b,&H28,&H18,_
&H"{A8A88C49-5EB2-4990-A1A2-0876022C854F}"=hex:1a,&H37,&H61,&H59,&H23,&H52,&H35,&H0c,&H7a,&H5f,&H20,_
&H17,&H2f,&H1e,&H1a,&H19,&H0e,&H2b,&H01,&H73,&H13,&H37,&H13,&H12,&H14,&H1a,&H15,&H2a,&H4e,&H2c,&H08,&H0d,&H20,&H1b,&H28,&H18,_
Set objShell = Nothing
WScript.Quit

Open in new window


Their is a problem with your reg file that dose not make seance their is 2 entry's that are sitting in limbo

32,36 that are sitting their is this an exact extract from the hive file
Avatar of mcpp661
mcpp661

ASKER

Everything I posted was cut and pasted from the .reg file I created by exporting that key. Several things I'm not understanding about your script though:

1. Since I'm only looking to edit HKCU I'm assuming that's the only constant I would need, and not the rest?

2. In the array, why does every value have to be prefixed with "&H"?

3. An oReg object was created but the objShell object was used to write the registry value, is this correct?

4.  Not sure I understand everything after the "ArrOfValue=" statement. You set the array equal to the binary entries, but then immediately after the first set you have "{A8A88C49-5EB2-4990-A1A2-0876022C854F}"=hex:1a" and so on. I don't understand this.

Please understand that I don't mean to sound like I'm questioning you, I just don't understand the work that was done and it's just as important that I understand because I want to learn this stuff as well. Thanks.
Hey,

Thats right but its just defining them so no need to worry about that

2 and 4. because you are playing with the binary form you need to set an array and then define the key when using vbs, as you are going from reg to vbs the interpreter need to know how to understand the values.

3. Yes that is correct

Im still abit off regarding the 36,32 key as its out of bounds and looks out of place can you double check the spacing ?
Avatar of mcpp661

ASKER

Just to be sure I'm going to VPN into work and export the key again and then attach it as a txt file. I'll have it posted in just a few minutes.
Avatar of mcpp661

ASKER

Here's the entire key. I have not edited the file. It was a reg file but I added a .txt extension.

Also, I'm still no understanding this part of the code:

ArrOfValue = Array(&H1a,&H37,&H61,&H59,&H23,&H52,&H35,&H0c,&H7a,&H5f,&H20,_      'Building array for handling BINARY Value
&H17,&H2f,&H1e,&H1a,&H19,&H0e,&H2b,&H01,&H73,&H13,&H37,&H13,&H12,&H14,&H1a,&H15,&H2a,&H4e,&H2c,&H08,&H0d,&H20,&H1b,&H28,&H18,_
&H"{A8A88C49-5EB2-4990-A1A2-0876022C854F}"=hex:1a,&H37,&H61,&H59,&H23,&H52,&H35,&H0c,&H7a,&H5f,&H20,_
&H17,&H2f,&H1e,&H1a,&H19,&H0e,&H2b,&H01,&H73,&H13,&H37,&H13,&H12,&H14,&H1a,&H15,&H2a,&H4e,&H2c,&H08,&H0d,&H20,&H1b,&H28,&H18,_

It looks like you have one of the registry values inside the array itself. That doesn't seem right to me?
Cookie-Settings-reg.txt
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mcpp661

ASKER

Works like a champ! Thanks Rob.