@echo off

REM MODIFIED REV7 27-Sep-06 16:40 PM - Added the SSRD detection so that the Build Partition is set to active. No BCD modifications are done.
REM MODIFIED REV6 27-Sep-06 15:55 PM - Added the {MEMDIAG} device settings
REM MODIFIED REV5 6-Sep-06 11:12 PM - Changed the path for the WINLOAD.EXE file from \Windows\System32 to \Windows\System32\Boot
REM MODIFIED REV4 6-Sep-06 12:40 PM - Boot device partitions use %USERPART% variable / Modified RP find routine
REM MODIFIED REV3 6-Sep-06 12:31 AM - Capitalized all drive letters in  the loop
REM MODIFIED REV2 6-Sep-06 12:30 AM - ADDED BCD ENTRIES FOR UP in UP/RP MODE
REM MODIFIED REV1 5-Sep-06 9:50 PM - MODIFIED RP DETECTION
REM MODIFIED REV0 5-Sep-06 12:25 PM - MBR command always with MBR.INI

ECHO.
ECHO %0: Modifying Vista's BCD > %SystemRoot%\System32\PATCH_CMD.LOG
ECHO %0: Modifying Vista's BCD
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG



Date /T >> %SystemRoot%\System32\PATCH_CMD.LOG
Date /T
Time /T >> %SystemRoot%\System32\PATCH_CMD.LOG
Time /T
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO ----------------------------------------------------------------------------- >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO -----------------------------------------------------------------------------
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG



REM -----------------------------------------------------------------------------
REM Showing the original state of the target BCD hive
REM -----------------------------------------------------------------------------
ECHO This is the original state of the target BCD hive: >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO This is the original state of the target BCD hive:
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /ENUM ALL /V >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /ENUM ALL /V
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
BCDEDIT /STORE %USERPART%\BOOT\BCD /ENUM ALL /V >> %SystemRoot%\System32\PATCH_CMD.LOG
BCDEDIT /STORE %USERPART%\BOOT\BCD /ENUM ALL /V
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO ----------------------------------------------------------------------------- >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO -----------------------------------------------------------------------------
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG


:FIND_BUILD_PARTITION
REM -----------------------------------------------------------------------------
REM Determining if we have an HP Build partition. If so, it means user has deployed SSRD disc.
REM We need to set the Build Partition as the active partition and quit... 
REM -----------------------------------------------------------------------------
ECHO Determining if we have an HP Build partition ... >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO Determining if we have an HP Build partition ... 
ECHO. >> %SystemRoot%\System32\PATCH_CMD.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:\SystemRecovery\RSVP\RSVP.EXE (
        
            ECHO %%a Contains RSVP.EXE, will assume this is an SSRD recovery ... >> %SystemRoot%\System32\PATCH_CMD.LOG
            ECHO %%a Contains RSVP.EXE, will assume this is an SSRD recovery ... 
            ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
            ECHO.
            
            ECHO SELECT VOLUME %%a >> ACTIVATEBP.LOG
            ECHO ACTIVE >> ACTIVATEBP.LOG
            ECHO EXIT >> ACTIVATEBP.LOG

        		ECHO DISKPART.EXE /s ACTIVATEBP.LOG >> %SystemRoot%\System32\PATCH_CMD.LOG
        		ECHO DISKPART.EXE /s ACTIVATEBP.LOG
        		DISKPART.EXE /s ACTIVATEBP.LOG

            ECHO   ...DISKPART returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
            ECHO   ...DISKPART returned %ErrorLevel%

            ECHO Apply the SoftThinks STANDARD Master Boot Record: >> %SystemRoot%\System32\PATCH_CMD.LOG
            ECHO Apply the SoftThinks STANDARD Master Boot Record:
            ECHO %SystemDrive%\WINDOWS\SYSTEM32\MBR.DLL /INI %SystemDrive%\WINDOWS\SYSTEM32\MBR.INI /Q >> %SystemRoot%\System32\PATCH_CMD.LOG
            ECHO %SystemDrive%\WINDOWS\SYSTEM32\MBR.DLL /INI %SystemDrive%\WINDOWS\SYSTEM32\MBR.INI /Q
            %SystemDrive%\WINDOWS\SYSTEM32\MBR.DLL /INI %SystemDrive%\WINDOWS\SYSTEM32\MBR.INI /Q 
            ECHO   ...MBRInst returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
            ECHO   ...MBRInst returned %ErrorLevel%
            ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
            ECHO.
            ECHO Batch done. >> %SystemRoot%\System32\PATCH_CMD.LOG
            ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
            
            GOTO ENDEND
        )
     )
)


:RP_LETTER
REM -----------------------------------------------------------------------------
REM Determining the Recovery Partition's drive letter
REM -----------------------------------------------------------------------------

ECHO Determining the Recovery Partition's drive letter ... >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO Determining the Recovery Partition's drive letter ... 
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.
ECHO Recovery Manager reports the following drive letters: >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO Recovery Manager reports the following drive letters:
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.
ECHO     User Partition    : %USERPART% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO     User Partition    : %USERPART%
ECHO     Recovery Partition: %RECOVERYPART% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO     Recovery Partition: %RECOVERYPART%
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.
ECHO Now searching for files specific to the Recovery Partition ... >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO Now searching for files specific to the Recovery Partition ...


SET RP=MISTERY
SET MYRP=MISTERY

REM ##########################################################################
REM   FIND THE RP
REM ##########################################################################
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 (
     copy %SystemRoot%\System32\RESTORE.STS %%a:\MASTER.LOG.COPY > NUL
     IF EXIST %%a:\MASTER.LOG.COPY (
         DEL %%a:\MASTER.LOG.COPY
         SET RP=%%a:
         GOTO FOUNDRPDRIVE
         )
     )
)

REM FAILED TO FIND RPDRIVE - SHOW ERROR AND RETURN
REM ==================================================================
ECHO.
ECHO RPDRIVE NOT FOUND - NO UPDATE FOR RP PERFORMED !
ECHO.
ECHO.

REM If we came down here, then Recovery Partition was not found
IF %RP%==MISTERY ECHO Recovery Partition not found ... this appears to be a UP-only scenario >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %RP%==MISTERY ECHO Recovery Partition not found ... this appears to be a UP-only scenario 

rem GOTO :ENDENDEND
GOTO UPONLY

:FOUNDRPDRIVE
ECHO Recovery Partition found on drive letter %RP%

rem GOTO :ENDENDEND

:RPFOUND
IF NOT %RP%==MISTERY ECHO File search shows the Recovery Partition is drive %RP% >> %SystemRoot%\System32\PATCH_CMD.LOG
IF NOT %RP%==MISTERY ECHO File search shows the Recovery Partition is drive %RP%
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.

REM Check for a mismatch in drive letters and display the result
REM Different results
IF NOT %RP%==%RECOVERYPART% ECHO !!! WARNING !!! >> %SystemRoot%\System32\PATCH_CMD.LOG
IF NOT %RP%==%RECOVERYPART% ECHO Recovery Manager and file search produced different drive letters >> %SystemRoot%\System32\PATCH_CMD.LOG
IF NOT %RP%==%RECOVERYPART% ECHO Continuing with Recovery Partition = %RP% >> %SystemRoot%\System32\PATCH_CMD.LOG
IF NOT %RP%==%RECOVERYPART% ECHO !!! WARNING !!!
IF NOT %RP%==%RECOVERYPART% ECHO Recovery Manager and file search produced different drive letters 
IF NOT %RP%==%RECOVERYPART% ECHO Continuing with Recovery Partition = %RP% 

REM Same results
IF %RP%==%RECOVERYPART% ECHO Both methods show the same drive letter, therefore, Recovery Partition = %RP% >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %RP%==%RECOVERYPART% ECHO Both methods show the same drive letter, therefore, Recovery Partition = %RP%
IF %RP%==%RECOVERYPART% ECHO Moving on to Vista's BCD hive modification ... >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %RP%==%RECOVERYPART% ECHO Moving on to Vista's BCD hive modification ...

REM Set the working variable for Recovery Partition to %RP%
SET MYRP=%RP%

ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO ----------------------------------------------------------------------------- >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO -----------------------------------------------------------------------------



REM -----------------------------------------------------------------------------
REM Determining an available GUID
REM -----------------------------------------------------------------------------

REM A list of five (5) pre-defined GUIDs
SET WINPE_GUID1={e9042df9-37b2-11db-80d7-0011d8c8bb47}
SET WINPE_GUID2={0a05baa7-37b3-11db-80d7-0011d8c8bb47}
SET WINPE_GUID3={2f7fb157-37b3-11db-80d7-0011d8c8bb47}
SET WINPE_GUID4={449f06af-37b3-11db-80d7-0011d8c8bb47}
SET WINPE_GUID5={537508b9-37b3-11db-80d7-0011d8c8bb47}


ECHO Verifying if pre-defined GUIDs already used... >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO Verifying if pre-defined GUIDs already used...
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.


REM Indirectly verify if specified WINPE_GUID already exists in the Vista hive
REM Select the first WINPE_GUID
SET WINPE_GUID=%WINPE_GUID1%
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES
BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.
REM Could not set the parameter because WINPE_GUID is not present
IF %ERRORLEVEL%==1 ECHO Found a unique GUID >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 ECHO Found a unique GUID
IF %ERRORLEVEL%==1 ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 ECHO.
IF %ERRORLEVEL%==1 ECHO Using GUID #1 ( %WINPE_GUID% )
IF %ERRORLEVEL%==1 ECHO Using GUID #1 ( %WINPE_GUID% ) >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 GOTO ADDFAILOVERSTUFF


REM Was able to set the parameter, therefore, the chosen WINPE_GUID is present; remove the change made
IF %ERRORLEVEL%==0 BCDEDIT /STORE %USERPART%\BOOT\BCD /DELETEVALUE %WINPE_GUID% MAXPROC
REM Select next WINPE_GUID
SET WINPE_GUID=%WINPE_GUID2%
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES
BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.
REM Could not set the parameter because WINPE_GUID is not present - OK, move on
IF %ERRORLEVEL%==1 ECHO Found a unique GUID >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 ECHO Found a unique GUID
IF %ERRORLEVEL%==1 ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 ECHO.
IF %ERRORLEVEL%==1 ECHO Using GUID #2 ( %WINPE_GUID% )
IF %ERRORLEVEL%==1 ECHO Using GUID #2 ( %WINPE_GUID% ) >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 GOTO ADDFAILOVERSTUFF


REM Was able to set the parameter, therefore, the chosen WINPE_GUID is present; remove the change made
IF %ERRORLEVEL%==0 BCDEDIT /STORE %USERPART%\BOOT\BCD /DELETEVALUE %WINPE_GUID% MAXPROC
REM Select next WINPE_GUID
SET WINPE_GUID=%WINPE_GUID3%
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES
BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.
REM Could not set the parameter because WINPE_GUID is not present - OK, move on
IF %ERRORLEVEL%==1 ECHO Found a unique GUID >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 ECHO Found a unique GUID
IF %ERRORLEVEL%==1 ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 ECHO.
IF %ERRORLEVEL%==1 ECHO Using GUID #3 ( %WINPE_GUID% )
IF %ERRORLEVEL%==1 ECHO Using GUID #3 ( %WINPE_GUID% ) >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 GOTO ADDFAILOVERSTUFF


REM Was able to set the parameter, therefore, the chosen WINPE_GUID is present; remove the change made
IF %ERRORLEVEL%==0 BCDEDIT /STORE %USERPART%\BOOT\BCD /DELETEVALUE %WINPE_GUID% MAXPROC
REM Select next WINPE_GUID
SET WINPE_GUID=%WINPE_GUID4%
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES
BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.
REM Could not set the parameter because WINPE_GUID is not present - OK, move on
IF %ERRORLEVEL%==1 ECHO Found a unique GUID >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 ECHO Found a unique GUID
IF %ERRORLEVEL%==1 ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 ECHO.
IF %ERRORLEVEL%==1 ECHO Using GUID #4 ( %WINPE_GUID% )
IF %ERRORLEVEL%==1 ECHO Using GUID #4 ( %WINPE_GUID% ) >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 GOTO ADDFAILOVERSTUFF


REM Was able to set the parameter, therefore, the chosen WINPE_GUID is present; remove the change made
IF %ERRORLEVEL%==0 BCDEDIT /STORE %USERPART%\BOOT\BCD /DELETEVALUE %WINPE_GUID% MAXPROC
REM Select the last available pre-defined WINPE_GUID
SET WINPE_GUID=%WINPE_GUID5%
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES
BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% MAXPROC YES
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.
REM Could not set the parameter because WINPE_GUID is not present - OK, move on
IF %ERRORLEVEL%==1 ECHO Found a unique GUID >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 ECHO Found a unique GUID
IF %ERRORLEVEL%==1 ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 ECHO.
IF %ERRORLEVEL%==1 ECHO Using GUID #5 ( %WINPE_GUID% )
IF %ERRORLEVEL%==1 ECHO Using GUID #5 ( %WINPE_GUID% ) >> %SystemRoot%\System32\PATCH_CMD.LOG
IF %ERRORLEVEL%==1 GOTO ADDFAILOVERSTUFF


REM Batch file was able to set the parameter, therefore, the chosen WINPE_GUID is present; remove the change made
IF %ERRORLEVEL%==0 BCDEDIT /STORE %USERPART%\BOOT\BCD /DELETEVALUE %WINPE_GUID% MAXPROC
REM The batch file has cleaned up any changes that it made

REM Batch file ran out of pre-defined WINPE_GUIDs to check for availability; cannot add auto failover stuff
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.
ECHO Sorry, could not add Auto Failover to Vista's BCD.  >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO Sorry, could not add Auto Failover to Vista's BCD.
REM However, the batch can still do other things that need to be done...
GOTO WRAPUP



:ADDFAILOVERSTUFF
REM ----------------------------------------------------------------------------------
REM Get going on things that will add the "Auto Failover" functionality to Vista's BCD
REM ----------------------------------------------------------------------------------

ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO ----------------------------------------------------------------------------- >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO -----------------------------------------------------------------------------
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
REM -----------------------------------------------------------------------------
REM In Vista's BCD, create an entry for the RAMDISK OPTIONS
REM -----------------------------------------------------------------------------

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /CREATE {ad6c7bc8-fa0f-11da-8ddf-0013200354d8} -d "Ramdisk Device Options" -DEVICE >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /CREATE {ad6c7bc8-fa0f-11da-8ddf-0013200354d8} -d "Ramdisk Device Options" -DEVICE
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /CREATE {ad6c7bc8-fa0f-11da-8ddf-0013200354d8} -d "Ramdisk Device Options" -DEVICE
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {ad6c7bc8-fa0f-11da-8ddf-0013200354d8} ramdisksdidevice partition=%MYRP% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {ad6c7bc8-fa0f-11da-8ddf-0013200354d8} ramdisksdidevice partition=%MYRP%
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {ad6c7bc8-fa0f-11da-8ddf-0013200354d8} ramdisksdidevice partition=%MYRP%
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {ad6c7bc8-fa0f-11da-8ddf-0013200354d8} ramdisksdipath \boot\boot.sdi >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {ad6c7bc8-fa0f-11da-8ddf-0013200354d8} ramdisksdipath \boot\boot.sdi
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {ad6c7bc8-fa0f-11da-8ddf-0013200354d8} ramdisksdipath \boot\boot.sdi
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG



ECHO ----------------------------------------------------------------------------- >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO -----------------------------------------------------------------------------
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.
REM -----------------------------------------------------------------------------
REM In Vista's BCD, create an entry for a Recovery Partition
REM -----------------------------------------------------------------------------

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /CREATE %WINPE_GUID% -D "Windows Recovery Environment" /APPLICATION OSLOADER >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /CREATE %WINPE_GUID% -D "Windows Recovery Environment" /APPLICATION OSLOADER
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /CREATE %WINPE_GUID% -D "Windows Recovery Environment" /APPLICATION OSLOADER
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% DEVICE RAMDISK=[%MYRP%]\sources\boot.wim,{ad6c7bc8-fa0f-11da-8ddf-0013200354d8} >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% DEVICE RAMDISK=[%MYRP%]\sources\boot.wim,{ad6c7bc8-fa0f-11da-8ddf-0013200354d8}
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% DEVICE RAMDISK=[%MYRP%]\sources\boot.wim,{ad6c7bc8-fa0f-11da-8ddf-0013200354d8}
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% PATH \WINDOWS\SYSTEM32\BOOT\WINLOAD.EXE >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% PATH \WINDOWS\SYSTEM32\BOOT\WINLOAD.EXE
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% PATH \WINDOWS\SYSTEM32\BOOT\WINLOAD.EXE
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% OSDEVICE RAMDISK=[%MYRP%]\sources\boot.wim,{ad6c7bc8-fa0f-11da-8ddf-0013200354d8} >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% OSDEVICE RAMDISK=[%MYRP%]\sources\boot.wim,{ad6c7bc8-fa0f-11da-8ddf-0013200354d8}
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% OSDEVICE RAMDISK=[%MYRP%]\sources\boot.wim,{ad6c7bc8-fa0f-11da-8ddf-0013200354d8}
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% SYSTEMROOT \WINDOWS >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% SYSTEMROOT \WINDOWS
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% SYSTEMROOT \WINDOWS
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% DETECTHAL YES >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% DETECTHAL YES
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% DETECTHAL YES
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% NX OPTIN >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% NX OPTIN
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% NX OPTIN
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% WINPE YES >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% WINPE YES
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% WINPE YES
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% RECOVERYENABLED YES >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% RECOVERYENABLED YES
BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% RECOVERYENABLED YES
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% RECOVERYSEQUENCE %WINPE_GUID% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% RECOVERYSEQUENCE %WINPE_GUID%
BCDEDIT /STORE %USERPART%\BOOT\BCD /SET %WINPE_GUID% RECOVERYSEQUENCE %WINPE_GUID%
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO ----------------------------------------------------------------------------- >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO -----------------------------------------------------------------------------
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG



REM -----------------------------------------------------------------------------
REM In Vista's BCD, assure the Recovery Partition entry is not shown on the menu
REM -----------------------------------------------------------------------------
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /TOOLSDISPLAYORDER %WINPE_GUID% /REMOVE >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /TOOLSDISPLAYORDER %WINPE_GUID% /REMOVE
BCDEDIT /STORE %USERPART%\BOOT\BCD /TOOLSDISPLAYORDER %WINPE_GUID% /REMOVE
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /TIMEOUT 30 >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /TIMEOUT 30
BCDEDIT /STORE %USERPART%\BOOT\BCD /TIMEOUT 30
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO ----------------------------------------------------------------------------- >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO -----------------------------------------------------------------------------
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG



REM -----------------------------------------------------------------------------
REM In Vista's BCD, add the Auto Failover stuff to the default Vista loader
REM -----------------------------------------------------------------------------
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} RECOVERYENABLED YES >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} RECOVERYENABLED YES
BCDEDIT /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} RECOVERYENABLED YES
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} RECOVERYSEQUENCE %WINPE_GUID% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} RECOVERYSEQUENCE %WINPE_GUID%
BCDEDIT /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} RECOVERYSEQUENCE %WINPE_GUID%
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO ----------------------------------------------------------------------------- >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO -----------------------------------------------------------------------------
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG



REM REM -----------------------------------------------------------------------------
REM REM In Vista's BCD, prevent the Username/Password dialog from showing up
REM REM  when booting Recovery Partition via "F8" -> "Repair Your Computer"
REM REM -----------------------------------------------------------------------------
REM ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} OSDEVICE BOOT >> %SystemRoot%\System32\PATCH_CMD.LOG
REM ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} OSDEVICE BOOT
REM BCDEDIT /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} OSDEVICE BOOT
REM ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
REM ECHO   ...BCDEDIT returned %ErrorLevel%
REM ECHO.
REM ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
REM ECHO ----------------------------------------------------------------------------- >> %SystemRoot%\System32\PATCH_CMD.LOG
REM ECHO -----------------------------------------------------------------------------
REM ECHO.
REM ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG


REM SKIPPED SO THAT UP ENTRIES ARE WRITTEN OK AS WELL IN RP/UP MODE
REM GOTO WRAPUP


:UPONLY
REM -------------------------------------------------------------------------------------------
REM Only User Partition present. Making sure Vista's BCD hive will point to the right partition
REM -------------------------------------------------------------------------------------------
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.
ECHO ----------------------------------------------------------------------------- >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO -----------------------------------------------------------------------------
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {BOOTMGR} DEVICE PARTITION=%USERPART% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {BOOTMGR} DEVICE PARTITION=%USERPART%
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {BOOTMGR} DEVICE PARTITION=%USERPART%
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} DEVICE PARTITION=%USERPART% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} DEVICE PARTITION=%USERPART%
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} DEVICE PARTITION=%USERPART%
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} OSDEVICE PARTITION=%USERPART% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} OSDEVICE PARTITION=%USERPART%
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {DEFAULT} OSDEVICE PARTITION=%USERPART%
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG

ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {MEMDIAG} OSDEVICE PARTITION=%USERPART% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {MEMDIAG} OSDEVICE PARTITION=%USERPART%
BCDEDIT.EXE /STORE %USERPART%\BOOT\BCD /SET {MEMDIAG} OSDEVICE PARTITION=%USERPART%
ECHO   ...BCDEDIT returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...BCDEDIT returned %ErrorLevel%
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO ----------------------------------------------------------------------------- >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO -----------------------------------------------------------------------------
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
GOTO WRAPUP



:WRAPUP
REM -----------------------------------------------------------------------------
REM Showing the current state of the target BCD hive
REM -----------------------------------------------------------------------------
ECHO This is the current state of the target BCD hive: >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO This is the current state of the target BCD hive:
ECHO.
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /ENUM ALL /V >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO BCDEDIT /STORE %USERPART%\BOOT\BCD /ENUM ALL /V
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.
BCDEDIT /STORE %USERPART%\BOOT\BCD /ENUM ALL /V >> %SystemRoot%\System32\PATCH_CMD.LOG
BCDEDIT /STORE %USERPART%\BOOT\BCD /ENUM ALL /V 
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.
ECHO ----------------------------------------------------------------------------- >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO -----------------------------------------------------------------------------
ECHO.
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG



REM -----------------------------------------------------------------------------
REM Setting the first partition (= User Partition) active
REM -----------------------------------------------------------------------------
ECHO Set the first partition (= User Partition) active >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO Set the first partition (= User Partition) active
ECHO %SystemDrive%\WINDOWS\SYSTEM32\MBR.DLL /INI %SystemDrive%\WINDOWS\SYSTEM32\MBR.INI /ACTIVE 1 /Q >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO %SystemDrive%\WINDOWS\SYSTEM32\MBR.DLL /INI %SystemDrive%\WINDOWS\SYSTEM32\MBR.INI /ACTIVE 1 /Q 
%SystemDrive%\WINDOWS\SYSTEM32\MBR.DLL /INI %SystemDrive%\WINDOWS\SYSTEM32\MBR.INI /ACTIVE 1 /Q 
ECHO   ...MBRInst returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...MBRInst returned %ErrorLevel%
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.



REM -----------------------------------------------------------------------------
REM Applying the SoftThinks' Master Boot Record
REM -----------------------------------------------------------------------------
ECHO Apply the SoftThinks Master Boot Record: >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO Apply the SoftThinks Master Boot Record:
ECHO %SystemDrive%\WINDOWS\SYSTEM32\MBR.DLL /INI %SystemDrive%\WINDOWS\SYSTEM32\MBR.INI /U /Q >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO %SystemDrive%\WINDOWS\SYSTEM32\MBR.DLL /INI %SystemDrive%\WINDOWS\SYSTEM32\MBR.INI /U /Q
%SystemDrive%\WINDOWS\SYSTEM32\MBR.DLL /INI %SystemDrive%\WINDOWS\SYSTEM32\MBR.INI /U /Q 
ECHO   ...MBRInst returned %ErrorLevel% >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO   ...MBRInst returned %ErrorLevel%
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO.
ECHO Batch done. >> %SystemRoot%\System32\PATCH_CMD.LOG
ECHO. >> %SystemRoot%\System32\PATCH_CMD.LOG
GOTO ENDEND



:ENDEND
ECHO -----------------------------------------------------------------------------
ECHO.
REM Make sure the LOG file does not get lost. Copy it to a safe location
IF EXIST %USERPART%\*.* ECHO Copying %SystemRoot%\System32\PATCH_CMD.LOG to %USERPART%\HP\RECOVERY\LOGS\
IF EXIST %USERPART%\*.* XCOPY %SystemRoot%\System32\PATCH_CMD.LOG %USERPART%\HP\RECOVERY\LOGS\ /Y /V /R
IF EXIST %USERPART%\*.* ECHO   ...XCOPY returned %ErrorLevel%
IF EXIST %USERPART%\*.* ECHO.
IF EXIST %MYRP%\*.* ECHO Copying %SystemRoot%\System32\PATCH_CMD.LOG to %MYRP%\HP\RECOVERY\LOGS\
IF EXIST %MYRP%\*.* XCOPY %SystemRoot%\System32\PATCH_CMD.LOG %MYRP%\HP\RECOVERY\LOGS\ /Y /V /R
IF EXIST %MYRP%\*.* ECHO   ...XCOPY returned %ErrorLevel%
IF EXIST %MYRP%\*.* ECHO.
ECHO Batch done. Bye.
ECHO.
ECHO.

:ENDENDEND
