@ECHO OFF

REM 29/09/2006 - REV3 - Ramdisk option 'ramdisksdidevice' now points to the BOOT.SDI in WinRE:\Boot folder. No need for this file in the Vista partition anymore.
REM 28/09/2006 - REV2 - Improved logging, different WINLOAD.EXE location and changed /STORE for ramdisk options.
REM 27/09/2006 - REV1 - Initial version.


REM -----------------------------------------------------------------------------
REM Start the LOG file
REM -----------------------------------------------------------------------------
SET LOG=HPRM_BCD_FIX.LOG
ECHO. %DATE%-%TIME%-[%~nx0]: START>> %LOG%
ECHO. >> %LOG%



REM -----------------------------------------------------------------------------
REM Determining if we have a SoftThinks Recovery Partition.
REM -----------------------------------------------------------------------------
ECHO Determining if we have a SoftThinks Recovery Partition ... >> %LOG%
ECHO Determining if we have a SoftThinks Recovery Partition ... 
ECHO. >> %LOG%
ECHO.
FOR %%a IN ( C D E F G H I J K L M N O P Q R S T U V W X Y Z ) DO (
        IF EXIST %%a:\PRELOAD\CSP.DAT IF EXIST %%a:\MASTER.LOG (
        
            ECHO %%a: Contains PRELOAD\CSP.DAT and MASTER.LOG, will assume this is the WinRE ... >> %LOG%
            ECHO %%a: Contains PRELOAD\CSP.DAT and MASTER.LOG, will assume this is the WinRE ...
            ECHO. >> %LOG%
            ECHO.
            
            SET WINRE_VOLUME=%%a
            
            GOTO ADD_AUTOFAILOVER_ENTRIES

            )
         )
      )
IF "%WINRE_VOLUME%"=="" GOTO END
REM -----------------------------------------------------------------------------



:ADD_AUTOFAILOVER_ENTRIES
REM -----------------------------------------------------------------------------
REM Set the WINRE boot configuration
REM -----------------------------------------------------------------------------
ECHO Set the WINRE boot configuration ... >> %LOG%
ECHO Set the WINRE boot configuration ... 
ECHO. >> %LOG%
ECHO.

ECHO BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /CREATE {ramdiskoptions} /d "RAM Disk Settings" >> %LOG
BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /CREATE {ramdiskoptions} /d "RAM Disk Settings" >> %LOG%
ECHO. >> %LOG%

ECHO BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {ramdiskoptions} ramdisksdidevice partition=%WINRE_VOLUME%: >> %LOG%
BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {ramdiskoptions} ramdisksdidevice partition=%WINRE_VOLUME%: >> %LOG%
ECHO. >> %LOG%

ECHO BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {ramdiskoptions} ramdisksdipath \boot\boot.sdi >> %LOG%
BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {ramdiskoptions} ramdisksdipath \boot\boot.sdi >> %LOG%
ECHO. >> %LOG%

ECHO BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /CREATE {572bcd55-ffa7-11d9-aae2-0007e994107d} -d "HP Recovery Manager" /application OSLOADER >> %LOG%
BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /CREATE {572bcd55-ffa7-11d9-aae2-0007e994107d} -d "HP Recovery Manager" /application OSLOADER >> %LOG%
ECHO. >> %LOG%

ECHO BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} device ramdisk=[%WINRE_VOLUME%:]\sources\boot.wim,{ramdiskoptions} >> %LOG%
BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} device ramdisk=[%WINRE_VOLUME%:]\sources\boot.wim,{ramdiskoptions} >> %LOG%
ECHO. >> %LOG%

ECHO BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} path \windows\system32\boot\winload.exe >> %LOG%
BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} path \windows\system32\boot\winload.exe >> %LOG%
ECHO. >> %LOG%

ECHO BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} osdevice ramdisk=[%WINRE_VOLUME%:]\sources\boot.wim,{ramdiskoptions} >> %LOG%
BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} osdevice ramdisk=[%WINRE_VOLUME%:]\sources\boot.wim,{ramdiskoptions} >> %LOG%
ECHO. >> %LOG%

ECHO BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} systemroot \windows >> %LOG%
BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} systemroot \windows >> %LOG%
ECHO. >> %LOG%

ECHO BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} detecthal yes >> %LOG%
BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} detecthal yes >> %LOG%
ECHO. >> %LOG%

ECHO BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} nx optin >> %LOG%
BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} nx optin >> %LOG%
ECHO. >> %LOG%

ECHO BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} winpe yes >> %LOG%
BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} winpe yes >> %LOG%
ECHO. >> %LOG%

ECHO BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} custom:46000010 yes >> %LOG%
BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /SET {572bcd55-ffa7-11d9-aae2-0007e994107d} custom:46000010 yes >> %LOG%
ECHO. >> %LOG%

ECHO BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /set {default} recoverysequence {572bcd55-ffa7-11d9-aae2-0007e994107d} >> %LOG%
BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /set {default} recoverysequence {572bcd55-ffa7-11d9-aae2-0007e994107d} >> %LOG%
ECHO. >> %LOG%

ECHO BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /set {default} recoveryenabled yes >> %LOG%
BCDEDIT.EXE /STORE %SystemDrive%\BOOT\BCD /set {default} recoveryenabled yes >> %LOG%
ECHO. >> %LOG%
REM -----------------------------------------------------------------------------
GOTO END



:END

ECHO. >> %LOG%
ECHO. %DATE%-%TIME%-[%~nx0]: END >> %LOG%
