|  | 
 
| 前两天有人询问如何卸载由我的安装批处理安装到vista启动项中的grub4dos,因此临时写了个 卸载批处理,但该批处理要求有安装时备份的bcd备份或保存的id临时文件,有一定限制。
 现重写卸载批处理,并与安装批处理合并。
 运行时首先判断bcd中是否已有grub4dos项目,有的话可选择“卸载”或“放弃”。没有的话就进行安装。
 卸载不需要备份文件,直接处理bcd中项目,通用性好。也可适用于卸载vista启动项中的其它项目。
 
 ----------------------------------
 @echo off
 rem by lianjiang
 COLOR f9
 set vid=
 set timeout=5
 set gname=GRUB for DOS
 set gname2=\grldr.mbr
 Set TIT=在Vista启动项中安装与卸载grub4dos项目的批处理 by lianjiang
 TITLE %TIT%
 bcdedit >temp_bcd.txt
 type temp_bcd.txt | find "Windows Boot Manager" >nul && goto bcd_1
 del temp_bcd.txt >nul 2>nul
 cls
 echo.
 echo   请以管理员身份运行。
 echo.
 pause
 :bcd_1
 type temp_bcd.txt | find "%gname2%" >nul && goto un_bcd
 bcdedit  /create /d "%gname%" /application bootsector >vid.ini
 for,/f,"tokens=2 delims={",%%i,In (vid.ini) Do (
 set vida=%%i
 )
 for,/f,"tokens=1 delims=}",%%i,In ("%vida%") Do (
 set vid={%%i}
 )
 echo %vid%>vid.ini
 bcdedit  /set %vid% device partition=%systemdrive%  >nul
 bcdedit  /set %vid% path %gname2% >nul
 bcdedit  /displayorder %vid% /addlast >nul
 bcdedit  /timeout  %timeout% >nul
 if exist grldr.mbr (
 copy grldr.mbr %systemdrive%\ /y
 goto exit
 ) else (
 echo.
 echo   稍后请自行把grldr.mbr拷贝到%systemdrive%\根目录
 echo.
 PING/n 5 127.1>NUL
 Goto exit
 )
 :un_bcd
 cls
 echo.
 echo   Vista的BCD启动项中存在grub4dos的项目["%gname2%"]。
 echo   ==============================================
 echo.
 set un_bcd=
 Set /P un_bcd=  是否需要卸载grub4dos项目 ?[y/是  n/否]:
 If %un_bcd%#==y# goto un_bcd_1
 Goto exit
 :un_bcd_1
 chcp 437
 for /f "tokens=1 delims=:" %%i In ('findstr /n %gname2%  temp_bcd.txt') Do (
 Set nid=%%i
 )
 set /a nid=%nid%-2
 findstr /n identifier temp_bcd.txt>temp_bcd1.txt
 for /f "tokens=2" %%i In ('findstr /n %nid%:identifier temp_bcd1.txt') Do (
 echo %%i>vid.ini
 )
 for,/f,"tokens=1",%%i,In (vid.ini) Do (
 set vid=%%i
 )
 bcdedit /delete %vid% /cleanup >nul
 bcdedit /timeout   %timeout% >nul
 bcdedit >temp_bcd.txt
 type temp_bcd.txt | find "%gname2%" >nul && goto un_bcd
 if exist %systemdrive%\grldr.mbr (
 attrib -h -s -r %systemdrive%\grldr.mbr >nul
 del %systemdrive%\grldr.mbr >nul
 )
 
 :exit
 del temp_bcd.txt >nul 2>nul
 del temp_bcd1.txt >nul 2>nul
 del vid.ini >nul 2>nul
 
 [ 本帖最后由 lianjiang 于 2009-11-17 08:44 编辑 ]
 | 
 |