Cómo utilizar el procesamiento por lotes BAT para cambiar el contenido especificado en el archivo .ini
Es más fácil usar VBS:
código vbs:
En caso de error, reanudar siguiente
Dim Fso, IniFl, Str, IniFn
p>IniFn=" " ' Escribe el nombre del archivo ini entre comillas dobles después del signo igual, por ejemplo: IniFn="configip.ini"
Establecer Fso = CreateObject("Scripting.FileSystemObject ")
Establecer IniFl = Fso.OpenTextFile ("c:\Windows\" & IniFn, 1)
Str = Reemplazar ( IniFl.ReadAll, " Item4=192.168.1.2 ","Item4=test.test.com")
Establecer IniFl = Fso.OpenTextFile ("c:\Windows\" & IniFn, 2)
IniFl.Write Str
IniFl.Close
Código de lote:
@echo off gt tmp.ini
set IniFn=
:: Escriba el nombre del archivo ini después del signo igual, como por ejemplo: set IniFn=configip.ini
for /f "tokens=1* delims=:" i in ( 'findstr /n ".*" c:\Windows\IniFn') hacer (
if "j"=="" (echo.gt; gt; tmp.ini) else (
echo j|find "Item4=192.168.1.2"gt;nulamp;amp;(
call set tp=jamp;call echo tp:192.168.1.2=test.test.comgt;gt; tmp.ini) ||(
gt; gt; tmp.ini echo j)
)
)
copiar tmp. ini c:\ Windows\IniFn /y gt;nul||(attrib -s -a -r -h c:\Windows\IniFnamp; copiar tmp.ini c:\Windows\IniFn /y gt;nul)
del tmp.ini
pausa