@echo off
set WinPE=%HI_DL%
bcdedit /create {ramdiskoptions} /d "Ramdisk options" 
bcdedit /set {ramdiskoptions} ramdisksdidevice partition=%WinPE%
bcdedit /set {ramdiskoptions} ramdisksdipath \boot\boot.sdi 

bcdedit /create /d "WinPE" /application OSLOADER >C:\Windows\Log\BOOTOPE_Create.log

for /f "tokens=1" %%u in (C:\Windows\Log\BOOTOPE_Create.log) do set GUID=%%u
echo %GUID% > C:\Windows\Log\BOOTOPE_GUID.log
Find /i "{" C:\Windows\Log\BOOTOPE_GUID.log
if %errorlevel%==0 goto Cont

for /f "tokens=2" %%u in (C:\Windows\Log\BOOTOPE_Create.log) do set GUID=%%u
echo %GUID% > C:\Windows\Log\BOOTOPE_GUID.log
Find /i "{" C:\Windows\Log\BOOTOPE_GUID.log
if %errorlevel%==0 goto Cont

for /f "tokens=3" %%u in (C:\Windows\Log\BOOTOPE_Create.log) do set GUID=%%u
echo %GUID% > C:\Windows\Log\BOOTOPE_GUID.log
Find /i "{" C:\Windows\Log\BOOTOPE_GUID.log
if %errorlevel%==0 goto Cont

for /f "tokens=4" %%u in (C:\Windows\Log\BOOTOPE_Create.log) do set GUID=%%u
echo %GUID% > C:\Windows\Log\BOOTOPE_GUID.log
Find /i "{" C:\Windows\Log\BOOTOPE_GUID.log
if %errorlevel%==0 goto Cont

for /f "tokens=5" %%u in (C:\Windows\Log\BOOTOPE_Create.log) do set GUID=%%u
echo %GUID% > C:\Windows\Log\BOOTOPE_GUID.log
Find /i "{" C:\Windows\Log\BOOTOPE_GUID.log
if %errorlevel%==0 goto Cont

:Cont
if exist %WinPE%\sources\boot.wim bcdedit /set %GUID% device ramdisk=[%WinPE%]\sources\boot.wim,{ramdiskoptions}
if exist %WinPE%\Recovery\WindowsRE\winre.wim bcdedit /set %GUID% device ramdisk=[%WinPE%]\Recovery\WindowsRE\winre.wim,{ramdiskoptions}
bcdedit /set %GUID% path \windows\system32\boot\winload.efi
if exist %WinPE%\sources\boot.wim bcdedit /set %GUID% osdevice ramdisk=[%WinPE%]\sources\boot.wim,{ramdiskoptions}
if exist %WinPE%\Recovery\WindowsRE\winre.wim bcdedit /set %GUID% osdevice ramdisk=[%WinPE%]\Recovery\WindowsRE\winre.wim,{ramdiskoptions}
bcdedit /set %GUID% systemroot \windows
bcdedit /set %GUID% winpe yes
bcdedit /set %GUID% detecthal yes
bcdedit /displayorder %GUID%
exit