mira, lo mejor es que utilices un programa que te haga el trabajo, y simplemente lo llamas con parámetros.
Hay uno muy bueno que se llama gsar.exe
http://gnuwin32.sourceforge.net/packages/gsar.htm
Esta es su ayuda:
gsar, ver 1.21 -- Copyright (C) 1992-2008 Tormod Tjaberg & Hans Peter Verne
Usage: gsar [options] [infile(s)] [outfile]
Options are:
-s<string> Search string
-r[string] Replace string. Use '-r' to delete the search string from the file
-i Ignore case difference when comparing strings
-B just display search & replace Buffers
-f Force overwrite of an existing output file
-o Overwrite the existing input file
-c[n] show textual Context of match, 'n' is number of bytes in context
-x[n] show context as a heX dump, 'n' is number of bytes in context
-b display Byte offsets of matches in file
-l only List filespec and number of matches (default)
-h suppress display of filespec when displaying context or offsets
-du convert a DOS ASCII file to UNIX (strips carriage return)
-ud convert a UNIX ASCII file to DOS (adds carriage return)
-F 'Filter' mode, input from stdin and eventual output to stdout
-G display the GNU General Public Licence
Ctrl characters may be entered by using a ':' in the string followed by the
ASCII value of the character. The value is entered using ':' followed by three
decimal digits or ':x' followed by two hex numbers. To enter ':' use '::'
Por ejemplo yo tengo el siguiente script para modificar rápidamente el boot.ini y activar dep para todos los programas y servicios. Esto normalmente, se hace yendo a Propiedades de pc ... y varios clics. En cambio yo automaticé el proceso. Activar dep para todos los programas es para aumentar la seguridad del equipo y que no te vulneren el sistema operativo con drivers.
@echo off
reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /f >nul 2>&1
(set file=%SystemDrive%\boot.ini)
attrib.exe -a -s -h -r "%file%" >nul 2>&1
gsar.exe -i -o -sNoExecute=OptIn -rNoExecute=OptOut "%file%" >nul 2>&1
if not errorlevel 1 (
reg.exe add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\NoExecuteState" /v LastNoExecuteRadioButtonState /t REG_DWORD /d 13013 /f >nul 2>&1
)
attrib.exe +a +s +h +r "%file%" >nul 2>&1
Lo que hace mi código es reemplazar en el boot.ini:
NoExecute=OptIn
por
NoExecute=OptOut
Si es que existe el texto OptIn, sino devuelve errorlevel 1 que significa que no reemplazo nada porque no encontró el texto de entrada en el archivo.
Yo te recomiendo este programa porque lo he probado y funciona bien.