@echo on
setlocal enabledelayedexpansion
if "%1"=="" (goto nonexist) else (goto exist)
:exist
if "%2"=="" (goto exist1) else (goto exist2)
:exist1
set win8VOL=c:
set winpeVOL=%1:
set win8path=c:\win8backup
set winpepath=c:\winpebackup
goto createPE
:exist2
set win8VOL=%1:
set winpeVOL=%2:
set win8path=%win8VOL%\win8backup
set winpepath=%win8VOL%\winpebackup
goto createPE
:nonexist
set win8VOL=c:
set winpeVOL=e:
set win8path=c:\win8backup
set winpepath=c:\winpebackup
goto createPE
:createPE
if exist %win8path% goto win8
bcdedit /export "%win8path%"
bcdedit /create {ramdiskoptions} /d "Windows PE"
bcdedit /set {ramdiskoptions} ramdisksdidevice partition=%winpeVOL%
bcdedit /set {ramdiskoptions} ramdisksdipath \boot\boot.sdi
bcdedit /create /d "Windows PE" -application osloader>guid.txt
set /p GUIDstr=<guid.txt
set ch1={
set newGUID=tmpstr
set GUID=abcd
set GUIDtmp=%GUIDstr%
:next
if not "%GUIDtmp%"=="" (
set /a num+=1
if "!GUIDtmp:~0,1!"=="%ch1%" set "GUID=%GUIDtmp%" && goto realID
set "GUIDtmp=%GUIDtmp:~1%"
goto next
)
set /a num=0
if "%num%"=="0" goto noGUID
:noGUID
@echo DO NOT FIND GUID ERROR
goto exit
:realID
set realGUID=%GUID:~0,38%
bcdedit /set %realGUID% device ramdisk=[%winpeVOL%]\sources\boot.wim,{ramdiskoptions}
bcdedit /set %realGUID% path \windows\system32\winload.efi
bcdedit /set %realGUID% osdevice ramdisk=[%winpeVOL%]\sources\boot.wim,{ramdiskoptions}
bcdedit /set %realGUID% systemroot \windows
bcdedit /set %realGUID% winpe yes
bcdedit /set %realGUID% nx optin
bcdedit /set %realGUID% detecthal yes
bcdedit /displayorder %realGUID% /addfirst
bcdedit /delete {current}
bcdedit /export "%winpepath%"
if exist guid.txt del guid.txt
set win8_bat=%win8VOL%\win8.bat
echo @echo off>%win8_bat%
echo setlocal enabledelayedexpansion>>%win8_bat%
echo if "%%1"=="" (goto nonexist) else (goto exist)>>%win8_bat%
echo :exist>>%win8_bat%
echo set win8vol=%%1:>>%win8_bat%
echo set win8path=%%win8vol%%\win8backup>>%win8_bat%
echo goto restore>>%win8_bat%
echo :nonexist>>%win8_bat%
echo set win8vol=c:>>%win8_bat%
echo set win8path=c:\win8backup>>%win8_bat%
echo goto restore>>%win8_bat%
echo :restore>>%win8_bat%
echo bcdedit /import %%win8path%%>>%win8_bat%
goto exit
:win8
if exist %winpepath% (goto winpe) else (goto exit)
:winpe
bcdedit /import %winpepath%
goto exit
:exit