Solved

Reg file to change a specific bit in a specific key

Posted on 2013-02-04
3
730 Views
Last Modified: 2013-02-24
Hi,

I want to remove the IE option of "Use automatic configuration script" via a batch or reg file.
I already found where this checkbox is in in the registry.

9th bit of this key :
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections] "DefaultConnectionSettings"

How can I make this change from a reg or batch file? I don't want to export the entire "Connections" container because it contains other keys as well that might chagne other system behavior. and I also want to share this solution (be it a reg file or other) with my colleagues, so they shouldn't get settings from my machine. best way would be to change the specific bit from 05 to 01.

Thanks
0
Comment
Question by:shootbox
3 Comments
 
LVL 9

Accepted Solution

by:
EMJSR earned 250 total points
Comment Utility
I have attached a .reg file (rename extension back to .reg) that will change the ninth bit accordingly. Only the listed key will be imported and changed, nothing else. To do this from a batch file, you can use the following command:

reg import connections.reg

Open in new window

You can obviously specify a path, too, such as...
reg import \\server\network\location\import.reg

Open in new window

etc.
connections.reg.txt
0
 
LVL 4

Expert Comment

by:Thomas WERNHER
Comment Utility
use the reg add from the cli.

btw, maybe a GPO would do it...?

Cheers.
T
0
 
LVL 82

Assisted Solution

by:oBdA
oBdA earned 250 total points
Comment Utility
That's actually not the 9th bit, but the 9th byte that you want to change.
Anyway, try the batch script below; it's currently in test mode and will only display the "reg add" command it would normally run. Remove the uppercase "ECHO" in front of "reg.exe add" in line 29 to run it for real.
@echo off
setlocal enabledelayedexpansion
set RegKey=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections
set RegVal=DefaultConnectionSettings
echo Reading current settings ...
for /f "tokens=2*" %%a in ('reg.exe query "%RegKey%" /v "%RegVal%" ^| find /i "%RegVal%"') do (set RegData=%%~b)
set /a ByteCount = 0
:StringToByteArrayLoop
	set /a ByteCount += 1
	set Byte[!ByteCount!]=!RegData:~0,2!
	set RegData=!RegData:~2!
if not "!RegData!"=="" (goto :StringToByteArrayLoop)
echo ... found %ByteCount% entries.
for /f "tokens=1 delims=[]" %%a in ('type "%~f0" ^| find /n "[REPLACE]"') do set DataStart=%%a
for /f "skip=%DataStart% tokens=1* delims== " %%i in ('type "%~f0"') do (
	if %%i gtr %ByteCount% (
		echo Replacement index %%i is outside of the length of the current data ^(%ByteCount%^).
		echo Operation cancelled.
		goto :eof
	)
	set NewValue=0%%j
	set NewValue=!NewValue:~-2!
	echo Byte[%%i]: !Byte[%%i]! --^> !NewValue!
	set Byte[%%i]=%%j
)
echo Writing settings back to registry ...
set RegData=
for /l %%i in (1, 1, %ByteCount%) do (set RegData=!RegData!!Byte[%%i]!)
ECHO reg.exe add "%RegKey%" /v "%RegVal%" /t REG_BINARY /d "%RegData%" /f
echo Done.

goto :eof
REM In the following section, enter the bytes to be replaced in the format <Index>=<NewValue>;
REM Index is one-based, not zero-based!
REM NewValue is the new hex value without leading "0x".
REM Leading zeros for the index are not allowed; for the value, leading zeros can be added, but are not required.
REM Example: 9=5 or 12=0C
[REPLACE]
9=05

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ZIP or ZIPX 8 69
Python Regex Problem 24 81
stamp tool on acrobat 1 25
windows 7 Home Premium can't add Remote Desktop users group 12 27
#Citrix #Internet Explorer #Enterprise Mode #IE 11 #IE 8
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now