源代码:
@echo off
pushd %~dp0
color 0b
set prog=Win7PE 专用安装程序
set l1= ╭══════════════════╮
set l2= ╭══┤ Win7PE 专用安装程序 ├══╮
set l3= ║ ╰══════════════════╯ ║
set l4= ║ ║
set l5= ╟════════════════════════╢
set l6= ║ 版权所有:qintag.com ║
set l7= ╰────────────────────────╯
title %prog%
set pefile=Win7PE.iso
set logfile=peinstall.log
set addattr=attrib +h
set delattr=attrib -s -h -r
:checkos
if /i not "%os%."=="windows_nt." goto systemerro
::判断系统版本并设置theos
ver|find /i " 6.1">nul &&set winver=win7&& set theos=win7
ver|find /i " 6.0">nul &&set winver=vista&& set theos=vista
ver|find /i " 5.0">nul &&set winver=winnt&& set theos=2000
ver|find /i " 5.1">nul &&set winver=winnt&& set theos=xp
ver|find /i " 5.2">nul &&set winver=winnt&& set theos=2003
goto start
::set choice=
set /p choice= 请选择要进行的操作 (1/2/q) ,然后按回车:
if "%choice%"=="" goto start
if not "%choice%"=="" set choice=%choice:~0,1%
if /i "%choice%"=="1" goto install
if /i "%choice%"=="2" goto uninstall
if /i "%choice%"=="q" exit
goto start
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:err1
cls
title %prog%——卸载
echo.
echo %l1%
echo %l2%
echo %l3%
echo %l4%
echo ║ 您的硬盘中好像已经安装了 Win7PE,您想怎么办? ║
echo %l4%
echo ║ [1] 卸载原有的 Win7PE,并且重新安装。 ║
echo ║ [2] 卸载原有的 Win7PE,并且不再安装。 ║
echo ║ 返回首页,重新选择安装选项。 ║
echo ║ [q] 退出安装 ║
echo %l5%
echo %l6%
echo %l7%
echo.
set choice=
set /p choice= 请选择要进行的操作 (1/2/b/q) ,然后按回车:
if "%choice%"=="" goto err1
if not "%choice%"=="" set choice=%choice:~0,1%
if /i "%choice%"=="1" set choi=1&&goto uninstall
if /i "%choice%"=="2" goto uninstall
if /i "%choice%"=="b" goto start
if /i "%choice%"=="q" exit
goto err1
exit
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:uninstall
set rp=
for %%i in (e d c) do if exist %%i:\config.sys set rp=%%i:
if exist %rp%\%logfile% for /f "eol=; tokens=2 delims=^=" %%i in ('find /i ^"Win7PE外挂位置^" %rp%\%logfile%') do set opd=%%i
if not "%u%"=="" set opd=%rp%
if exist %rp%\%pefile% %delattr% %rp%\%pefile%&&del %rp%\%pefile% /q>nul 2>nul
if exist %rp%\grldr %delattr% %rp%\grldr&&del %rp%\grldr /q>nul 2>nul
if exist %rp%\grldr.mbr %delattr% %rp%\grldr.mbr&&del %rp%\grldr.mbr /q>nul 2>nul
if exist %rp%\menu.lst %delattr% %rp%\menu.lst&&del %rp%\menu.lst /q>nul 2>nul
if exist %rp%\%logfile% %delattr% %rp%\%logfile%&&del %rp%\%logfile% /q>nul 2>nul
if exist %rp%\Win7PE.iso %delattr% %rp%\Win7PE.iso&&del %rp%\Win7PE.iso /q>nul 2>nul
if exist %opd%\Win7PE rd %opd%\Win7PE /s /q>nul 2>nul
find /i "%rp%\Win7PE" %rp%\boot.ini>nul 2>nul
if "%errorlevel%"=="0" %delattr% %rp%\boot.ini&&del %rp%\boot.ini
%delattr% %rp%\boot.ini>nul 2>nul
if /i "%theos%"=="vista" (%delattr% %rp%\boot.ini&&del %rp%\boot.ini>nul 2>nul)
if /i "%theos%"=="win7" (%delattr% %rp%\boot.ini&&del %rp%\boot.ini>nul 2>nul)
if exist %rp%\boot.bak (
%delattr% %rp%\boot.bak
type %rp%\boot.bak|find /i /v "%rp%\Win7PE">%rp%\boot.ini
) else (
if exist %rp%\boot.ini copy %rp%\boot.ini %rp%\boot.bak /y>nul 2>nul
if exist %rp%\boot.bak type %rp%\boot.bak|find /i /v "c:\Win7PE">%rp%\boot.ini
)
if exist %rp%\boot.bak %delattr% %rp%\boot.bak&&del %rp%\boot.bak>nul 2>nul
if exist %rp%\boot.ini %addattr% %rp%\boot.ini >nul 2>nul
set rp=
title %prog%——卸载完成
echo.&&echo.&&echo 卸载完成,请按任意键退出 。。。
pause>nul 2>nul
exit
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:install
if not exist ..\sources\Win7PE.WIM goto err2
set rp=
for %%i in (e d c) do if exist %%i:\config.sys set rp=%%i:
set pedir=%rp%\%pefile%
if exist %pedir% goto err1
cls
echo.
echo.
echo. 当前是 %theos% 操作系统
echo.
echo.
echo ║ 请选择 Win7PE 引导方式: ║
echo. ║ ║
echo ║ [a] Grub引导ISO方式 ║
echo ║ ║
echo ║ BCD引导WIM方式 ║
echo ║ ║
echo ║ [e] 退出安装 ║
echo.
echo.
echo.
echo.
::set choice=
set /p choice= 请选择要进行的操作 (a/b/e) ,然后按回车:
if "%choice%"=="" goto start
if not "%choice%"=="" set choice=%choice:~0,1%
if /i "%choice%"=="a" goto instiso
if /i "%choice%"=="b" goto instwim
if /i "%choice%"=="e" exit
goto install
:bootmgr
echo on
rem 设定主入口bootmgr的参数....
bcdedit %bcddir% /set {bootmgr} device partition=%rp%
bcdedit %bcddir% /set {bootmgr} inherit {globalsettings}
bcdedit %bcddir% /set {bootmgr} locale "zh-CN"
bcdedit %bcddir% /timeout 2
for %%b in (C D E F) do (
if exist %%b:\boot.ini (
Bcdedit /create {ntldr} /d "Windows XP Professional"
Bcdedit /set {ntldr} device partition=%%b:
Bcdedit /set {ntldr} path \ntldr
Bcdedit /displayorder {ntldr} /addlast
bcdedit %bcddir% /displayorder %w7id% %w7peid% {ntldr}
bcdedit %bcddir% /default %w7id%
goto okwim
)
)
bcdedit %bcddir% /displayorder %w7id% %w7peid%
bcdedit %bcddir% /default %w7id%
goto okwim
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:okiso
title %prog%——ISO映像安装完成
if "%op%"=="" call :setextra
echo.
echo 安装Win7PE外置程序,请稍等...
if not "%op%"=="" xcopy ..\WinPE /e %op%\WinPE\ /y /h /r>nul 2>nul
if "%u%"=="" call :pelog
cls
echo.
echo 已经成功将 Win7PE 安装到您的本地硬盘,启动方式为Grub引导ISO映像。
echo.
if "%u%"=="" (
echo 外置程序 文件夹按照您的设置,复制到了 %op% 盘。
echo.
if exist %rp%\boot.ini echo 系统分区中的boot.ini备份为boot.bak。
)
echo.
echo 如果您需要将 Win7PE 卸载,请重新运行本安装程序。
echo.
echo 请按任意键退出......
pause>nul 2>nul
exit
:okwim
title %prog%——WIM映像安装完成
if "%op%"=="" call :setextra
echo.
echo 安装Win7PE外置程序,请稍等...
if not "%op%"=="" xcopy ..\WinPE /e %op%\WinPE\ /y /h /r>nul 2>nul
if "%u%"=="" call :pelog
cls
echo.
echo 已经成功将 Win7PE 安装到您的本地硬盘,启动方式为bcd引导WIM映像。
echo.
if "%u%"=="" (
echo 外置程序 文件夹按照您的设置,复制到了 %op% 盘。
echo.
)
echo.
echo 如果需要将 Win7PE 卸载,请重新运行本安装程序。
echo.
echo 请按任意键退出......
pause>nul 2>nul
exit
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:instiso
title %prog%——Win7PE安装
echo.
echo.
echo 您选择了由Grub启动ISO映像安装。
echo.&&echo.&&echo 按任意键继续 ......
pause>nul 2>nul
copy menu.lst %rp%\menu.lst /y>nul 2>nul
copy grldr %rp%\grldr /y>nul 2>nul
if exist %rp%\grldr.mbr copy grldr.mbr %rp%\grldr.mbr /y>nul 2>nul
md %rp%\temp_pe3
md %rp%\temp_pe3\sources
copy ..\bootmgr %rp%\temp_pe3\bootmgr /y>nul 2>nul
xcopy ..\boot /e %rp%\temp_pe3\boot\ /y /h /r>nul 2>nul
copy ..\sources\Win7PE.WIM %rp%\temp_pe3\sources\Win7PE.WIM /y>nul 2>nul
cls
echo.
echo 正在制作 iso 镜像,请稍等...
echo.
oscdimg.exe -b"pe.bif" -h -n -lWin7PE -o -t01/01/2012,00:00:00 "%rp%\temp_pe3" "%rp%\Win7PE.iso"
if not exist %rp%\boot.ini copy boot.ini %rp%\boot.ini /y>nul 2>nul
if exist %rp%\boot.ini %delattr% %rp%\boot.ini
if exist %rp%\boot.ini if exist %rp%\boot.bak %delattr% %rp%\boot.bak
if exist %rp%\boot.ini copy %rp%\boot.ini %rp%\boot.bak>nul 2>nul
if exist %rp%\boot.ini echo %rp%\grldr="Windows 7 PE Edition">>%rp%\boot.ini
if "%u%"=="" call :pelog
goto okiso
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:setextra
cls
if "%noop%"=="yes" echo 错误:您设定的分区不存在或写保护,请按任意键重新设定。&&echo.
set /p op=请设定 外置程序 存放的分区符[不需要冒号,例如 d(推荐)]:
echo.&&echo.
if "%op%"=="" goto setextra
if not "%op%"=="" set op=%op:~0,1%:
set testfile=%op%\imgtest_%random%.mt
cd.>%testfile%
if not exist %testfile% set noop=yes&&goto setextra
del %testfile% /q>nul 2>nul
goto :eof