批处理 修改boot.ini文件

来源:百度知道 编辑:UC知道 时间:2024/05/21 06:44:31
求一批处理 修改boot.ini文件
要求:

查找内容为“multi(0)disk(0)rdisk(0)partition(4)\WINDOWS="Windows 2002" /noexecute=optin ”这一行,并将其删除。

或者说查找某行内容为“Windows 2002”,并将其所在行删除

注意:不知道其ID是多少,所以不能用 bootcfg /delete /id 2 这种语句

首先查找"windows 2002"所在行的行号,赋值给%target%
然后查找每一个"启动项目 ID:"的行号,赋值给%id%
小于target且最大的%id%即为"windows 2002"所在的id
然后用bootcfg /delete /id %id%删除即可

@echo off
for /f "delims=[,]" %%a in ('bootcfg /query^|find /i /n "Windows 2002"') do set target=%%a
for /f "delims=[,],: tokens=1,3" %%a in ('bootcfg /query^|find /i /n "启动项目 ID:"') do if %%a lss %target% set /a id=%%b
bootcft /delete /id %id%