|
本帖最后由 oym2016 于 2025-4-6 14:22 编辑
在楼主的基础上 经deepseek_r 检测
@echo off
pushd %~dp0
title 添加PE VHD到硬盘
setlocal ENABLEDELAYEDEXPANSION
set "src=%~1"
if "%~1"=="" (echo.&set /p "src=请将PE的WIM/VHDX文件拖放到本窗口后按回车键:")
set "src=%src:"=%"
for %%a in ("%src%") do (set "fn=%%~na"&set "fx=%%~xa")
:process_drv
cls&echo.
:: 查找可用驱动器号
set "pan="
for %%i in (Q R S T U V W X Y Z) do (if not exist %%i:\ set "pan=%%i"&goto :mount_vol)
:mount_vol
if defined pan (
mountvol !pan!: /s >nul 2>&1 && (
echo "系统UEFI启动.使用ESP分区efi\microsoft\boot\BCD."
set "bd=!pan!"
set "sdi=\EFI\boot.sdi"
set "ext=efi"
set "is_efi=1"
if /i "%fx%"==".vhdx" goto process_vhd
echo.&set /p "drv=请输入PE添加到的盘符(回车ESP分区; C D E F... ):"
)
) else (
echo "非UEFI启动.使用C:盘BCD."
set bd=C
set "sdi=\boot\boot.sdi"
set "ext=exe"
set "is_efi=0"
if /i "%fx%"==".vhdx" goto process_vhd
)
:chksdi
if not exist "%bd%:%sdi%" (
if exist "C:\Windows\Boot\DVD\EFI\boot.sdi" (
set "sdi1=C:\Windows\Boot\DVD\EFI\boot.sdi"
) else if exist "%~dp0boot.sdi" (
set "sdi1=%~dp0boot.sdi"
) else (
echo.
set /p "sdi1=请将boot.sdi文件拖放到本窗口后按回车键:"
set "sdi1=!sdi1:"=!"
)
if exist "!sdi1!" copy "!sdi1!" "%bd%:%sdi%" >nul
)
:chkwim
if not "!drv!"=="" (
if not exist "%drv%:\sources\%fn%%fx%" (
if not exist "%drv%:\sources" md "%drv%:\sources"
if exist "%src%" (
copy "%src%" "%drv%:\sources" >nul
)
)
)else (
if not exist "%bd%:\sources\%fn%%fx%" (
if not exist "%bd%:\sources" md "%bd%:\sources"
if exist "%src%" (
copy "%src%" "%bd%:\sources" >nul
)
)
)
:bcd
if defined pan mountvol !pan!: /d >nul 2>&1
for /f "tokens=1*" %%c in ('Dism.exe /Get-ImageInfo /ImageFile:"%src%" /Index:1 ^| findstr /i "名称:"') do (
set "desc=%%d"
)
if "!desc!"=="" set "desc=Windows PE_%fn%%fx%"
call :osid
if !is_efi! equ 1 (
set "wim=[boot]\sources\%fn%%fx%"
if exist !drv!: set "wim=[%drv%:]\sources\%fn%%fx%"
) else (
set "wim=[%bd%:]\sources\%fn%%fx%"
)
echo BCD_%fn%%fx%:
echo.
echo 系统存储:SystemBCD
echo 设备文件:!wim!
echo GUID :!guid!
echo 菜单标题:!desc!
echo 启动文件:\Windows\system32\boot\winload.!ext!
echo.
pause
bcdedit /enum {ramdiskoptions} | findstr /i "boot.sdi" >nul || (
bcdedit /create {ramdiskoptions} >nul
bcdedit /set {ramdiskoptions} ramdisksdidevice boot >nul
bcdedit /set {ramdiskoptions} ramdisksdipath "%sdi%" >nul
)
bcdedit /set !guid! device "ramdisk=!wim!,{ramdiskoptions}"
bcdedit /set !guid! osdevice "ramdisk=!wim!,{ramdiskoptions}"
bcdedit /set !guid! path "\Windows\system32\boot\winload.!ext!"
bcdedit /set !guid! systemroot \Windows >nul
bcdedit /set !guid! detecthal 1 >nul
bcdedit /set !guid! winpe 1 >nul
bcdedit /displayorder !guid! /addlast >nul
bcdedit /timeout 3 >nul
bcdedit /set {bootmgr} displaybootmenu 1 >nul
bcdedit /set {bootmgr} nointegritychecks 1 >nul
:end
echo 请按任意键结束...
pause >nul
if defined pan mountvol !pan!: /d >nul 2>&1
exit
:process_vhd
if defined pan mountvol !pan!: /d >nul 2>&1
set "vhd_path=%src%"
set "desc=Windows_%fn%%fx%"
call :osid
echo.
echo BCD_%fn%%fx%:
echo.
echo 系统存储:SystemBCD
echo 设备文件:"[!vhd_path:~0,2!]!vhd_path:~2!"
echo GUID :!guid!
echo 菜单标题:!desc!
echo 启动文件:\Windows\system32\winload.!ext!
echo.
pause
bcdedit /set !guid! device "vhd=[!vhd_path:~0,2!]!vhd_path:~2!"
bcdedit /set !guid! osdevice "vhd=[!vhd_path:~0,2!]!vhd_path:~2!"
bcdedit /set !guid! path "\Windows\system32\winload.!ext!" >nul
bcdedit /set !guid! systemroot \Windows >nul
bcdedit /displayorder !guid! /addlast >nul
bcdedit /timeout 5 >nul
echo VHD启动项 [!guid!] 已创建
pause
exit
:osid
for /f "tokens=2 delims={}" %%a in ('bcdedit /create /d "%desc%" /application osloader 2^>nul') do (
set "guid={%%a}"
set "guid=!guid:~0,38!"
)
exit /b |
|