Replace a text in a reg file by a other text

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DOSAM
Posts: 3
Joined: 01 Nov 2006 11:04

Replace a text in a reg file by a other text

#1 Post by DOSAM » 01 Nov 2006 11:07

Ok let's try to explain. I'm writing a bat file that first detects in wich folder the bat file is, that I allready have and it saves it in variable: %BatchFile%
but now, I need to replace in a reg files where stand installdir = "%DIR%" and that must be replaced by the founded folder of the variable %BatchFile%

Hope someone can help me

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 02 Nov 2006 00:29

DOSAM,

To replace a single line in a text file you might want to try something like this:

Code: Select all

set BatchFile=%~dp0
set filename=myregfile.reg
set findthis=installdir

(for /f "tokens=1,* delims=]" %%a in ('"find /n /v "" "%filename%""') do (
        echo.%%b|find "%findthis%">NUL && ( echo.%findthis% = "%BatchFile%"
        ) || ( echo.%%b )
))>"%filename%.tmp"
move /y "%filename%.tmp" "%filename%"

DOS IT HELP? :wink:

DOSAM
Posts: 3
Joined: 01 Nov 2006 11:04

#3 Post by DOSAM » 02 Nov 2006 05:17

haha yes thanks you ;)

DOSAM
Posts: 3
Joined: 01 Nov 2006 11:04

#4 Post by DOSAM » 04 Nov 2006 13:43

ok now, i need big help! look in that code u wrote that replaces a full line and it makes some things unreadable for regedit and for commands to: let's try to explain. first if I run the code for reg file then it makes at start of reg file a enter and then starts the text for example:
first:

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\EA GAMES\Need For Speed Underground]
"DisplayName"="Need For Speed Underground"
"Installed From"="%cd\\"
"3D Device Description"="NVIDIA GeForce4 Ti 4200 [D3D]"
"3D Card"="Unknown D3D"
"Thrash Driver"="dx"
"Group"="D3D"
"D3D Device"=dword:00000000
"Triple Buffer"=dword:00000000
"Hardware Acceleration"=dword:00000001
"Thrash Resolution"="640x480"
"CacheSize"="1351315456"
"SwapSize"="0"
"Language"="English US"
"Locale"="en_us"
"Registration"="SOFTWARE\\Electronic Arts\\EA GAMES\\Need For Speed Underground\\ergc"
"CD Drive"="C:\\Downloads\\Need For Speed Underground\\Need For Speed Underground\\"
"Install Dir"="C:\\Downloads\\Need For Speed Underground\\Need For Speed Underground\\"
"Product GUID"="{A99968BE-C155-474C-0089-33239DEE1CE2}"
"Region"="region_us"

[HKEY_LOCAL_MACHINE\SOFTWARE\EA GAMES\Need For Speed Underground\1.0]
"Language"=dword:00000001
"DisplayName"="Need For Speed Underground"
"LanguageName"="English US"



after running the batch file.

Code: Select all

 
Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\SOFTWARE\EA GAMES\Need For Speed Underground]
"DisplayName"="Need For Speed Underground"
"Installed From"="%cd\\"
"3D Device Description"="NVIDIA GeForce4 Ti 4200 [D3D]"
"3D Card"="Unknown D3D"
"Thrash Driver"="dx"
"Group"="D3D"
"D3D Device"=dword:00000000
"Triple Buffer"=dword:00000000
"Hardware Acceleration"=dword:00000001
"Thrash Resolution"="640x480"
"CacheSize"="1351315456"
"SwapSize"="0"
"Language"="English US"
"Locale"="en_us"
"Registration"="SOFTWARE\\Electronic Arts\\EA GAMES\\Need For Speed Underground\\ergc"
_DIR_ = "C:\Documents and Settings\***\My Documents\"
_DIR_ = "C:\Documents and Settings\***\My Documents\"
"Product GUID"="{A99968BE-C155-474C-0089-33239DEE1CE2}"
"Region"="region_us"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\EA GAMES\Need For Speed Underground\1.0]
"Language"=dword:00000001
"DisplayName"="Need For Speed Underground"
"LanguageName"="English US"

do u see there at first line, there comes a enter, how do I remover it in dos cuz otherwise regedit will not accept the reg file anymore.

2nd. looks to the lines where first stands path: _DIR_ and look then in the 2nd there u see lines start with _DIR_ but actually, _DIR_ had to be removed and that install dir and other had must stay stand there! is there a way to fix?
btw, here is code of my BAT file:

Code: Select all

@echo off
title CCZ REG iNJECTOR
echo Injecting REG file, wait...
::Get the current batch file's short path
for %%x in (%0) do set BatchPath=%%~dpsx
for %%x in (%BatchPath%) do set BatchPath=%%~dpsx
echo.
echo reg file
echo getting directory..
echo.
echo.
echo directory = %BatchPath%
echo now getting it into a textfile...
set BatchFile=%~dp0
set filename=myregfile.reg
set findthis=_DIR_

(for /f "tokens=1,* delims=]" %%a in ('"find /n /v "" "%filename%""') do (
        echo.%%b|find "%findthis%">NUL && ( echo.%findthis% = "%BatchFile%") || ( echo.%%b )
))>"%filename%.tmp"
move /y "%filename%.tmp" "%filename%"
pause


hope u can help me =)
thanks anyway ;)

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#5 Post by DosItHelp » 04 Nov 2006 17:33

Like this?

Code: Select all

@echo off
title CCZ REG iNJECTOR
echo.Getting directory..
set BatchFile=%~dp0
echo.directory = %BatchPath%
set filename=myregfile.reg
set findthis1=CD Drive
set findthis2=Install Dir
(for /f "tokens=1,* delims=]" %%a in ('"type "%filename%"|find /n /v """') do (
    echo.%%b|find "%findthis1%">NUL && ( echo."%findthis1%"="%BatchFile:\=\\%") || (
    echo.%%b|find "%findthis2%">NUL && ( echo."%findthis2%"="%BatchFile:\=\\%") || (
        echo.%%b))
))>"%filename%.tmp"
move /y "%filename%.tmp" "%filename%"
pause


:wink:

Post Reply