1

I need to create a batch file that adds text to the last line in a boot.ini file, for example the last line of my boot.ini is :

multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect

i need to add /bootlogo /noguiboot option, therefore the line of the boot.ini should be modified in :

multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect /bootlogo /noguiboot

Can i do this with a batch file ? There's another way to do this ?

Thanks.

8 Answers 8

0

Don't know if I understand your question but adding a line is quite easy:

echo "blabla" >> c:\boot.ini

1
  • no, with echo "blabla" >> c:\boot.ini you append text on the next line of the file, i need to append text in the last line of the file, no create a new line...
    – aleroot
    Aug 25, 2010 at 11:59
0

I'm not sure you can do that with the vanilla WinXP command line. Try the freeware GPatch.

0

I'd probably use SED for this:

@echo off
cd /d c:\
attrib -r -h -s boot.ini
sed -e "s/fastdetect$/fastdetect \/bootlogo \/noguiboot/" boot.ini > boot.$$$
ren boot.ini boot.old
ren boot.$$$ boot.ini
attrib +r +h +s boot.ini

SED is available as part of GnuWin or you can find a standalone version here. Also, as I've written it, the SED above will make the substitution on all lines ending with 'fastboot'. You could make the search string longer to guarantee that you're operating only on one specific line.

2
  • There's no reason to perform a search and replace, appending to the file is fine. He just wants a way that doesn't output a new line.
    – Hello71
    Aug 25, 2010 at 14:18
  • If the last line ends with one or more newlines, the "echo" technique will append the two new switches (as in your example, which I've tested under XP) on a new line by themselves. Also, your COPY will fail because boot.ini is a hidden system file.
    – BillP3rd
    Aug 25, 2010 at 14:23
0

Right click my computer, choose properties. Click the Advanced tab and then under STARTUP and RECOVERY, select Settings. On the next screen under System Startup, click Edit. This opens the Boot.ini file with Notepad to allow you to add these and other switches or make other changes.

0

You can do this with the following workaround:

set rand=%RANDOM%
echo /bootlogo /noguiboot > %TEMP%\%rand%.txt
attrib -R -S -H C:\boot.ini
copy C:\boot.ini+%TEMP%\%rand%.txt C:\boot.ini
attrib +R +S +H C:\boot.ini
del %TEMP%\%rand%.txt

Basically, this creates a temporary file, echos your data to the end of it, then uses copy to concatenate C:\boot.ini with the temporary file.

0
0

I've found a solution :

attrib -r -s -h %SystemDrive%\boot.ini
gsar.exe -o -i -s:032:047bootlogo:032:047noguiboot -r %SystemDrive%\boot.ini
gsar.exe -o -sfastdetect -rfastdetect:032:047bootlogo:032:047noguiboot %SystemDrive%\boot.ini
attrib +r +s +h %SystemDrive%\boot.ini
0

Well, boot.ini is system file. Before modifying that, you should remove that attribute.

Read and try my solution. It searches for all Windows boot options that the folder is named WINDOWS (all uppercase) in boot.ini. Then it recreates boot.ini accordingly your choice - to add or remove "/bootlogo /noguiboot" - for each Windows boot option.

@echo off
SETLOCAL EnableDelayedExpansion

echo.This batch is an editor for all Windows boot options in boot.ini.
echo.- Limitations: works only with 8 parameters and detects only Windows instalations with folders named "WINDOWS" - all uppercased
echo.

::save the current path
set pathbak=%cd%
for /f "tokens=1* delims=:" %%a in ("%pathbak%") do (
  set drvbak=%%a
)

::put bellow the drive where boot.ini is
c:
cd \

::remove system and hidden attributes from boot.ini
attrib -r -s -h boot.ini

::create new file
echo.>boot.new

::read boot.ini
for /f "tokens=1* delims=\" %%a in (boot.ini) do (
  if "%%b"=="" (
    echo.%%a>>boot.new
  )
  for /f "tokens=1* delims==" %%c in ("%%b") do (
    ::find Windows boot options
    if "%%c" neq "WINDOWS" (
      echo.%%a\%%b>>boot.new
    ) else (
      if "%%b"=="WINDOWS" (
        echo.%%a\%%b>>boot.new
      ) else (
        ::split parameters
        for /f "tokens=1,2,3,4,5,6,7,8* delims=/" %%e in ("%%d") do (
          ::remove spaces after strings
          for /f "delims= " %%n in ("%%a") do set __a=%%n
          for /f "delims= " %%n in ("%%c") do set __c=%%n
          for /f "delims=" %%n in ("%%e") do set __e=%%n
          for /f "delims= " %%n in ("%%f") do set __f=%%n
          for /f "delims= " %%n in ("%%g") do set __g=%%n
          for /f "delims= " %%n in ("%%h") do set __h=%%n
          for /f "delims= " %%n in ("%%i") do set __i=%%n
          for /f "delims= " %%n in ("%%j") do set __j=%%n
          for /f "delims= " %%n in ("%%k") do set __k=%%n
          for /f "delims= " %%n in ("%%l") do set __l=%%n
          for /f "delims= " %%n in ("%%m") do set __m=%%n

          echo.Found a WINDOWS boot option in partition "!__a!":
          echo.- text seen on boot: !__e!
          if "!__f!" neq "" (
            echo.- parameter 1: /!__f!
          ) else (
            echo.- parameter 1:
          )
          if "!__g!" neq "" (
            echo.- parameter 2: /!__g!
          ) else (
            echo.- parameter 2:
          )
          if "!__h!" neq "" (
            echo.- parameter 3: /!__h!
          ) else (
            echo.- parameter 3:
          )
          if "!__i!" neq "" (
            echo.- parameter 4: /!__i!
          ) else (
            echo.- parameter 4:
          )
          if "!__j!" neq "" (
            echo.- parameter 5: /!__j!
          ) else (
            echo.- parameter 5:
          )
          if "!__k!" neq "" (
            echo.- parameter 6: /!__k!
          ) else (
            echo.- parameter 6:
          )
          if "!__l!" neq "" (
            echo.- parameter 7: /!__l!
          ) else (
            echo.- parameter 7:
          )
          if "!__m!" neq "" (
            echo.- parameter 8: /!__m!
          ) else (
            echo.- parameter 8:
          )
          echo.
          set bootlogo=0
          if "!__f!"=="bootlogo" set bootlogo=1
          if "!__g!"=="bootlogo" set bootlogo=1
          if "!__h!"=="bootlogo" set bootlogo=1
          if "!__i!"=="bootlogo" set bootlogo=1
          if "!__j!"=="bootlogo" set bootlogo=1
          if "!__k!"=="bootlogo" set bootlogo=1
          if "!__l!"=="bootlogo" set bootlogo=1
          if "!__m!"=="bootlogo" set bootlogo=1
          set noguiboot=0
          if "!__f!"=="noguiboot" set noguiboot=1
          if "!__g!"=="noguiboot" set noguiboot=1
          if "!__h!"=="noguiboot" set noguiboot=1
          if "!__i!"=="noguiboot" set noguiboot=1
          if "!__j!"=="noguiboot" set noguiboot=1
          if "!__k!"=="noguiboot" set noguiboot=1
          if "!__l!"=="noguiboot" set noguiboot=1
          if "!__m!"=="noguiboot" set noguiboot=1
          set /a bootlogonoguiboot=!bootlogo!+!noguiboot!
          if "!bootlogonoguiboot!"=="2" (
            echo.Do you want to remove /bootlogo /noguiboot parameters for that Windows boot option [y or n]?
            set /p choice1=
            if "!choice1!"=="y" (
              set newoption=!__a!\!__c!=!__e!
              if "!__f!" neq "" if "!__f!" neq "bootlogo" if "!__f!" neq "noguiboot" set newoption=!newoption! /!__f!
              if "!__g!" neq "" if "!__g!" neq "bootlogo" if "!__g!" neq "noguiboot" set newoption=!newoption! /!__g!
              if "!__h!" neq "" if "!__h!" neq "bootlogo" if "!__h!" neq "noguiboot" set newoption=!newoption! /!__h!
              if "!__i!" neq "" if "!__i!" neq "bootlogo" if "!__i!" neq "noguiboot" set newoption=!newoption! /!__i!
              if "!__j!" neq "" if "!__j!" neq "bootlogo" if "!__j!" neq "noguiboot" set newoption=!newoption! /!__j!
              if "!__k!" neq "" if "!__k!" neq "bootlogo" if "!__k!" neq "noguiboot" set newoption=!newoption! /!__k!
              if "!__l!" neq "" if "!__l!" neq "bootlogo" if "!__l!" neq "noguiboot" set newoption=!newoption! /!__l!
              if "!__m!" neq "" if "!__m!" neq "bootlogo" if "!__m!" neq "noguiboot" set newoption=!newoption! /!__m!
              echo.!newoption!>>boot.new
            ) else (
              echo.%%a\%%b>>boot.new
            )
            set choice1=
          ) else (
            if "!bootlogonoguiboot!" neq "2" echo.Do you want to add /bootlogo /noguiboot parameters for that Windows boot option [y or n]?
            (
              set /p choice1=
              if "!choice1!"=="y" (
                set newoption=!__a!\!__c!=!__e!
                if "!__f!" neq "" if "!__f!" neq "bootlogo" if "!__f!" neq "noguiboot" set newoption=!newoption! /!__f!
                if "!__g!" neq "" if "!__g!" neq "bootlogo" if "!__g!" neq "noguiboot" set newoption=!newoption! /!__g!
                if "!__h!" neq "" if "!__h!" neq "bootlogo" if "!__h!" neq "noguiboot" set newoption=!newoption! /!__h!
                if "!__i!" neq "" if "!__i!" neq "bootlogo" if "!__i!" neq "noguiboot" set newoption=!newoption! /!__i!
                if "!__j!" neq "" if "!__j!" neq "bootlogo" if "!__j!" neq "noguiboot" set newoption=!newoption! /!__j!
                if "!__k!" neq "" if "!__k!" neq "bootlogo" if "!__k!" neq "noguiboot" set newoption=!newoption! /!__k!
                if "!__l!" neq "" if "!__l!" neq "bootlogo" if "!__l!" neq "noguiboot" set newoption=!newoption! /!__l!
                if "!__m!" neq "" if "!__m!" neq "bootlogo" if "!__m!" neq "noguiboot" set newoption=!newoption! /!__m!
                set newoption=!newoption! /bootlogo /noguiboot
                echo.!newoption!>>boot.new
              ) else (
                echo.%%a\%%b>>boot.new
              )
              set choice1=
            )
          )
        )
      )
    )
  )
)

cls
echo......................
type boot.new
echo......................

::replace current boot.ini
copy boot.ini boot.bak.%random%
copy boot.new boot.ini

::restore system and hidden attributes
attrib +r +s +h boot.ini

::restore previous path
%drvbak%:
cd %pathbak%
0

To edit boot.ini you could try:

run>sysdm.cpl

On the Advanced tab click Settings and then Edit. This will open boot.ini in a text editor (Notepad in my case). Make your edits and save (having first saved a copy of the original just in case!).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .