|
Win7PE 专用安装程序
修改小马 Win7PE 专用安装程序,ISO和WIM映像不同启动方式,问题不少,请高手指点完善。
目的:适用于XP、Win7和PE下的win7PE 的硬盘安装。
安装后,单系统、双系统启动菜单保持原有结构。如XP+Win7pe、Win7+Win7pe、XP+Win7+Win7pe,PE下安装可自动判断系统结构并安装。我是批处理的外行,所以求高手修改。
源代码:
@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
:systemerro
cls
echo.
echo.
echo 注意:未经测试,本软件可能不适用于非 windows pe/2000/xp/2003/vista/win7 操作系统。
echo 按回车键退出安装程序
pause >nul
exit
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:start
cls
title %prog%——安装
echo.
echo %l1%
echo %l2%
echo %l3%
echo %l4%
echo ║ 请选择安装方式: ║
echo %l4%
echo ║ [1] 普通安装/启动 (硬 盘 安 装) ║
echo ║ ║
echo ║ [2] 卸载 Win7PE 程序 ║
echo ║ ║
echo ║ [q] 退出安装 ║
echo %l5%
echo %l6%
echo %l7%
echo.
echo 您现在使用的是 windows %theos% 操作系统 !
if "%theos%"=="xp" echo ( 或 windows xp 核心的 Win7PE )
if "%theos%"=="2003" echo ( 或 windows 2003 核心的 Win7PE )
if "%theos%"=="vista" echo ( 请确保您拥有管理员权限以及关闭了uac,否则安装可能失败 )
if "%theos%"=="win7" echo ( 请确保您拥有管理员权限以及关闭了uac,否则安装可能失败 )
echo.
::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
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:err2
cls
title %prog%——找不到文件 Win7PE.WIM
echo.
echo.
echo.
echo.
echo 请将此安装文件放在 \sources 目录下,并检查此 Win7PE 的目录结构
echo.
echo.
echo 按任意键退出...&&pause >nul
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
:instwim
title %prog%——Win7PE安装
echo.
echo.
echo 您选择了由BCD启动Win7PE.WIM映像安装。
echo.&&echo.&&echo 按任意键继续 ......
pause>nul 2>nul
copy ..\sources\Win7PE.WIM %rp%\Win7PE.WIM /y>nul 2>nul
if EXIST %rp%\boot\bcd copy ..\bootmgr %rp%\bootmgr /y>nul 2>nul
set bcddir=/store %rp%\boot\bcd
if EXIST %rp%\boot\bcd goto hasbcd
echo.
echo.
echo 提示:%rp%\boot\下无bcd文件,将重建%rp%\boot\bcd!
echo 按任意键继续 ......
pause>nul 2>nul
goto nobcd
:hasbcd
echo on
if EXIST %rp%\boot\bcd attrib -h -s -r %rp%\boot\bcd.*&&del %rp%\boot\bcd.* >nul
goto win7
:nobcd
echo on
rem xcopy ..\boot /e %rp%\boot\ /y /h /r>nul 2>nul
copy ..\sources\bcd*.* %rp%\Windows\system32\ /y>nul 2>nul
echo.
bcdedit /createstore %rp%\boot\bcd
rem 建立 bootmgr 主入口....
bcdedit %bcddir% /create {bootmgr} /d "Windows Boot Manager"
rem 建立内存诊测程序项....
bcdedit %bcddir% /create {memdiag} /d "Windows memdiag"
bcdedit %bcddir% /toolsdisplayorder {memdiag} /addlast
for %%a in (C D E F) do (
if not exist %%a:\config.sys (
echo 本地磁盘中无NT6系统
goto win7pe
)
)
:Win7
rem 建立winvista/win7/win2008系统启动项......
for /f "delims={,} tokens=2" %%a in ('bcdedit %bcddir% /create /d "Windows 7 Setup" /application osloader ') do set w7id={%%a}
bcdedit %bcddir% /set %w7id% device partition=%rp%
bcdedit %bcddir% /set %w7id% path \windows\system32\winload.exe
bcdedit %bcddir% /set %w7id% locale zh-CN
bcdedit %bcddir% /set %w7id% inherit {bootloadersettings}
bcdedit %bcddir% /set %w7id% osdevice partition=%rp%
bcdedit %bcddir% /set %w7id% systemroot \windows
bcdedit %bcddir% /set %w7id% nx optin
bcdedit %bcddir% /displayorder %w7id% /addlast
:win7pe
rem 建立win7pe_wim开机菜单启动项....
bcdedit %bcddir% /create {ramdiskoptions} /d "win7pe"
bcdedit %bcddir% /set {ramdiskoptions} ramdisksdidevice partition=%rp%
bcdedit %bcddir% /set {ramdiskoptions} ramdisksdipath \boot\boot.sdi
rem BCD菜单建立"Windows7PE"项,只跟bcdtool查看有关,与开机菜单不是同一个东西
for /f "delims={,} tokens=2" %%a in ('bcdedit %bcddir% -create /d "Windows7PE" -application osloader ') do set w7peid={%%a}
bcdedit %bcddir% -set %w7peid% device ramdisk="[%rp%]\boot\boot.wim,{ramdiskoptions}"
bcdedit %bcddir% -set %w7peid% osdevice ramdisk="[%rp%]\boot\boot.wim,{ramdiskoptions}"
bcdedit %bcddir% -set %w7peid% path \windows\system32\boot\winload.exe
bcdedit %bcddir% -set %w7peid% locale zh-CN
bcdedit %bcddir% -set %w7peid% inherit {bootloadersettings}
bcdedit %bcddir% -set %w7peid% systemroot \windows
bcdedit %bcddir% -set %w7peid% detecthal yes
bcdedit %bcddir% -set %w7peid% winpe yes
bcdedit %bcddir% -set %w7peid% ems yes
bcdedit %bcddir% -displayorder %w7peid% -addlast
: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
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:pelog
>%rp%\%logfile% cd.
>>%rp%\%logfile% echo ;此文件为 Win7PE 的安装logfile,请不要随意删除
>>%rp%\%logfile% echo ;否则可能会造成 Win7PE 的卸载不够彻底!!!
>>%rp%\%logfile% echo.
>>%rp%\%logfile% echo Win7PE镜像文件=%pefile%
>>%rp%\%logfile% echo Win7PE外挂位置=%op%
>>%rp%\%logfile% echo Win7PE安装日期=%date% %time%
%addattr% %rp%\%logfile%
goto :eof |
|