Find replace registry batch script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
powerhouse
Posts: 1
Joined: 23 Jan 2013 03:27

Find replace registry batch script

#1 Post by powerhouse » 23 Jan 2013 03:40

Hi Gurus, please help.
I'm trying to figure out why my reg import command is not working in the script below(a mod of the find/replace scripts).....I took your sample and modified it. When I run the reg import fileName.reg from the DOS it works fine but when included in the script below it does nothing and I cannot find why. I can see the export completed correctly and the format looks ok to me. When I use the the reg import command on the same exported file it works fine. Below is the code.

Thx......

Code: Select all

@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
REM  This script updates the Windows Registry for the

REM update Admin Nodes
set service1Key=HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\MyService1\Parameters
set service2Key=HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\MyService2\Parameters

echo updating [%service1Key%]
call :updateRegKeys %service1Key%
echo updating [%service2Key%]
call :updateRegKeys %service2Key%

SET count=3
set looper=1

FOR /L %%A IN (1,1,%count%) DO (call :updateAllServers %%A)
GOTO:EOF

:updateAllServers
SET domainKey=HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\MyDomain%looper%\Parameters
SET otherDomainKey=HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\MyOtherDomain%looper%\Parameters
echo [%domainKey%]
echo [%otherDomainKey%]
echo .
call :updateRegKeys %domainKey%
call :updateRegKeys %otherDomainKey%
set /a looper+=1
goto:eof

:updateRegKeys
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
set "registrykey=%1"
set findv="-Xms512m"
set replacev="-Xms512m something that is long"
echo "Updating registry values, please wait..."
REG EXPORT "%registrykey%" origReg.txt
call :findReplace %findv% %replacev% origReg.txt > newkeys.reg
reg import newkeys.reg
del /q newkeys.reg origReg.txt

:findReplace
REM finds and replaces a string
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
set "line=%%B"
if defined line (
    call set "line=echo.%%line:%~1=%~2%%"
    for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.
)
goto:eof

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Find replace registry batch script

#2 Post by abc0502 » 23 Jan 2013 03:52

try adding

Code: Select all

ping localhost -n 5 >nul
before you import the .reg file and after calling the function, it might be happening fast when you call the find and replace function and the import command.
change the time to suite your requirements.

Post Reply