|
本帖最后由 wjgyz740526 于 2021-9-4 18:04 编辑
经常给别人做系统,很多时候没有pe,就想着做系统的时候最好一起把pe给装到本地硬盘,然后就有了这个脚本(系统安装过程调用即可)。脚本自动判断,如果是efi引导,且ESP分区容量足够的话,就把pe安装到ESP分区,否则把pe安装到磁盘最后一个分区。
用的drvtype是第三方工具,这个在pe下可用,wmic方式pe一般都不能用 ,有这个需求的自己改下
脚本如下:
@echo off
color 3F
setlocal EnableDelayedExpansion
pecmd mess= 安装Windows PE 维护平台...\n本程序会在你的Windows系统菜单上添加PE启动项! \n因本人技术所限,可能存在风险,请知悉!@警告!#ok *5000
pecmd.exe show -1:-1
bcdedit /enum {current}|find "system32\winload.exe">nul
if %errorlevel% equ 1 (
set bootmode=UEFI
set winload=winload.efi
) else (
set bootmode=Legacy
set winload=winload.exe
)
if exist %~dp0tmp.txt del %~dp0tmp.txt
for /f "tokens=1-5 delims= " %%a in ('drvtype -a ^|find ":"') do echo %%d>>%~dp0tmp.txt
for /f "delims= " %%a in (%~dp0tmp.txt) do echo %%a & set HDDList=!HDDList!%%a
for %%b in (!HDDList!) do (
set tmpVol=%%b
call :check
if /i "!judge!" == "ok" (
if /i "%bootmode%" == "uefi" (
if exist !tmpVol!\EFI\Microsoft\Boot\BCD set efi=!tmpVol!
)
)
set LastVol=!tmpVol!
)
if not "!efi!" == "" (
set LastVol=!efi!
pecmd TEAM~ mess= 当前系统引导模式为 %bootmode% ,且ESP分区!efi!容量足够!\n建议安装PE到此分区!\n\n按是开始安装,按否请手工指定安装位置!@警告!#YN *5000 $Y ~WRIT *fv -,$+0,YESNO |find /i "yes"
)
echo %ERRORLEVEL%
if %ERRORLEVEL% EQU 0 (
call :InstPE
) else (
set LastVol=
call :Custom
set /p LastVol=<%~dp0y.txt
if not "!LastVol!" == "" call :InstPE
)
del %~dp0tmp.txt
del %~dp0y.txt
exit
:Custom
if exist %~dp0custom.wcs del %~dp0custom.wcs
if exist %~dp0y.txt del %~dp0y.txt
echo Windows1 >%~dp0custom.wcs
echo _SUB Windows1,W370H200,,MESS= 程序即将关闭!@确定#OK*3000,,0 >>%~dp0custom.wcs
echo LABE Label1,L90T35W300H70,安装Windows PE 维护平台..%~dp0n\n\n请指定要安装的目标分区: 盘 >>%~dp0custom.wcs
echo IMAG Image1,L18T37W60H60,C:\Windows\system32\shell32.dll#40 >>%~dp0custom.wcs
echo LIST List1,L230T68W35H32,,, >>%~dp0custom.wcs
echo ITEM Button1,L150T120W90H30,取消,TEAM MESS= 程序即将关闭!@确定#OK*3000 ^| KILL \%Windows1%,, >>%~dp0custom.wcs
echo ITEM Button2,L255T120W90H30,确定,call _Select >>%~dp0custom.wcs
for %%a in (%HDDList%) do echo ENVI @List1.addsel=%%a >>%~dp0custom.wcs
echo _END >>%~dp0custom.wcs
echo _SUB _Select >>%~dp0custom.wcs
echo MESS= 你选择将PE安装到%%List1%%盘,按确定之后开始安装! @确定#OK*3000 >>%~dp0custom.wcs
echo WRIT %~dp0y.txt,$1,%%List1%% >>%~dp0custom.wcs
echo KILL \%Windows1% >>%~dp0custom.wcs
echo _END >>%~dp0custom.wcs
pecmd load %~dp0custom.wcs
goto:eof
:check
for /f "tokens=1-4 delims= " %%i in ('dir %tmpVol% ^|find /i "可用字节"') do (
set space=%%k
)
set space=!space:,=!
if !space! lss 450000000 (set judge=err) else set judge=ok
goto:eof
:InstPE
if not exist %LastVol%\BOOT md %LastVol%\BOOT
copy /y %~dp0*.wim %LastVol%\BOOT\
copy /y %~dp0BOOT.SDI %LastVol%\BOOT\
del %~dp0*.wim
bcdedit.exe /timeout 9
bcdedit.exe /set {current} bootmenupolicy Legacy
set id1={%time:~6,2%%time:~9,2%ffff-8d96-11de-8e71-fffffffffffa}
set id2={%time:~6,2%%time:~9,2%ffff-8d96-11de-8e71-fffffffffffb}
bcdedit /create %id2% /d "Windows 10 PE 维护平台" /device
bcdedit /set %id2% ramdisksdidevice partition=%LastVol%
bcdedit /set %id2% ramdisksdipath \boot\boot.sdi
bcdedit /create %id1% /d "Windows 10 PE 维护平台" /application osloader
bcdedit /set %id1% device ramdisk=[%LastVol%]\boot\1064.WIM,%id2%
bcdedit /set %id1% osdevice ramdisk=[%LastVol%]\boot\1064.WIM,%id2%
bcdedit /set %id1% path \windows\system32\boot\%winload%
bcdedit /set %id1% description "Windows 10 PE 维护平台"
bcdedit /set %id1% locale zh-CN
bcdedit /set %id1% inherit {bootloadersettings}
bcdedit /set %id1% systemroot \windows
bcdedit /set %id1% detecthal Yes
bcdedit /set %id1% winpe Yes
bcdedit /set %id1% ems no
bcdedit /displayorder %id1% /addlast
attrib +r +h +s +a %LastVol%\BOOT
goto:eof
上一个代码在虚拟机里写的,没考虑多硬盘的情况,所以会出错。
现在的判断逻辑是:有esp分区且容量足够就提示安装到esp分区,选择否就跳出指定安装窗口,你可以自定义安装位置。如果esp分区容量不够,且在3秒内没有点击则自动安装到最后一个容量足够的分区。
感谢红毛和5大
特别说明,包里的是pecmd_cli版,不用这个版本,程序判断会出错
完整的附件:
安装pe到硬盘.7z
(951.8 KB, 下载次数: 245)
|
评分
-
查看全部评分
|