I found some very helpful articles on this site, but I'm having trouble with this one...
Here is the applicable batch code:
@echo off > %AppData%\PROGRAM\NEW.INI setLocal EnableDelayedExpansion find "DESIRED STRING" < %AppData%\PROGRAM\EXISTING.INI > nul if not errorlevel 1 goto :FOUND for /f "tokens=1 delims= " %%a in ('find /n "[SERVERS]" ^< %AppData%\PROGRAM\EXISTING.INI') do ( set /a i=%%a ) for /f "tokens=* delims= " %%a in (%AppData%\PROGRAM\EXISTING.INI) do ( set /a n+=1 echo %%a >> %AppData%\PROGRAM\NEW.INI if !i! equ !n! echo DESIRED STRING >> %AppData%\PROGRAM\NEW.INI ) REM --DEBUG NEW INI FILE edit %AppData%\PROGRAM\NEW.INI goto :EOF :FOUND echo FOUND IN EXISTING.INI FILE - ABORTED! pause goto :EOF :EOF
The EXISTING.INI file has blank lines in it that are not copied to a NEW.INI file, therefore when inserting new lines into the NEW.INI file they are inserted at the incorrect locations.
For example - A new string should be inserted at line 120 of the EXISTING.INI, however the NEW.INI is without the blank lines of the EXISTING.INI file and what was line 120 is now line 113 so the new string is inserted at the "new" line 120 ("old" line 127) of the NEW.INI file.
Does that make sense? Any idea how I can make this batch copy the blank lines to the NEW.INI file?
The plan is to distribute as a logon script that modifies that particular INI file on the client's machine. All our clients are Windows based, so if there is a better way to do this with VBS - I'm all ears!
Thanks in advance!