I wanted you to look at a modified version of your script.
Have any pointers?
@ECHO OFF
CLS
ECHO -----------------------------------------------------------
ECHO Checking to see if the PC is booted in BIOS or UEFI mode.
wpeutil UpdateBootInfo
for /f "tokens=2* delims= " %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') DO SET Firmware=%%B
ECHO Note: delims is a TAB followed by a space.
IF x%Firmware%==x ECHO ERROR: Can't figure out which firmware we're on.
IF x%Firmware%==x ECHO Common fix: In the command above:
IF x%Firmware%==x ECHO for /f "tokens=2* delims= "
IF x%Firmware%==x ECHO ...replace the spaces with a TAB character followed by a space.
IF x%Firmware%==x GOTO END
IF %Firmware%==0x1 ECHO The PC is booted in BIOS mode.
IF %Firmware%==0x2 ECHO The PC is booted in UEFI mode.
ECHO -----------------------------------------------------------
CD %~dp0
IF EXIST GPT.ini DEL GPT.ini
IF EXIST MBR.ini DEL MBR.ini
IF EXIST tempgpt.ini DEL tempgpt.ini
IF EXIST tempmbr.ini DEL tempmbr.ini
TITLE Prepare Disk for WinNTSetup3
:PRIVILEGECHECK
NET SESSION >nul 2>&1
IF %errorlevel% == 0 (
GOTO SELECTTYPE
) else (
GOTO GETPRIVILEGE
)
:NOPRIVILEGE
ECHO Prepare Hard Disk for WinNTSetup3 GPT (UEFI) or MBR (BIOS)
ECHO -----------------------------------------------------------
ECHO Warning, Elevated Privilege is Required
ECHO.
ECHO RE-OPEN AS AN ADMINISTRATOR
ECHO THE PROGRAM WILL NOW EXIT
ECHO.
ECHO -----------------------------------------------------------
ECHO.
PAUSE
EXIT
:GETPRIVILEGE
SET "params=%*"
SETLOCAL EnableDelayedExpansion
CD /d "%~dp0" && ( IF EXIST "%temp%\getadmin.vbs" DEL "%temp%\getadmin.vbs" ) && fsutil dirty query %systemdrive% 1>NUL 2>NUL || ( ECHO Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k CD ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && EXIT /B )
GOTO NOPRIVILEGE
:SELECTTYPE
ECHO Prepare Hard Disk for WinNTSetup3 GPT (UEFI) or MBR (BIOS)
ECHO Please note: Only Windows x64 Will work with GPT
ECHO -----------------------------------------------------------
ECHO.
CHOICE /C MG /M "Are you setting up for MBR or GPT "
IF %ERRORLEVEL% == 1 GOTO INITMBR
IF %ERRORLEVEL% == 2 GOTO INITGPT
ECHO.
ECHO Invalid selection! Please choose a valid selection.
ECHO.
PAUSE
GOTO SELECTTYPE
EXIT
:INITMBR
CLS
ECHO Prepare Hard Disk for WinNTSetup3 MBR (BIOS)
ECHO -----------------------------------------------------------
ECHO.
ECHO list disk >> list.txt
diskpart /s list.txt
DEL list.txt>nul
ECHO.
SET /p disk="Which disk number would you like to prepare? (e.g. 0): "
IF [%DISK%] == [] GOTO INITMBR
ECHO.
ECHO --WARNING-- This will FORMAT the selected disk and ERASE ALL DATA
ECHO.
ECHO You selected disk ---^> %disk%
ECHO.
CHOICE /C YN /M "Is this correct "
IF %ERRORLEVEL% == 1 GOTO INITMBR2
CLS
ECHO Preperation Aborted, No changes have been made...
ECHO.
PAUSE
EXIT
:INITMBR2
SET BOOTDRV="S"
SET DATADRV="W"
ECHO sel dis %disk% >> initmbr.txt
ECHO clean >> initmbr.txt
ECHO convert mbr >> initmbr.txt
rem == 1. System partition ======================
ECHO create partition primary size=350 >> initmbr.txt
ECHO format quick fs=ntfs label="System" >> initmbr.txt
ECHO assign letter=%BOOTDRV% >> initmbr.txt
ECHO active >> initmbr.txt
rem == 2. Windows partition =====================
rem == a. Create the Windows partition =======
ECHO create partition primary >> initmbr.txt
rem == b. Create space for the recovery image
ECHO shrink minimum=500 >> initmbr.txt
rem ** Note, adjust the size to match
rem the size of the recovery image.
rem == c. Prepare the Windows partition ======
ECHO format quick fs=ntfs label="Windows" >> initmbr.txt
ECHO assign letter %DATADRV% >> initmbr.txt
rem == 3. Recovery image partition ==============
ECHO create partition primary >> initmbr.txt
ECHO format quick fs=ntfs label="Recovery image" >> initmbr.txt
ECHO assign letter="R" >> initmbr.txt
ECHO set id=27 >> initmbr.txt
ECHO exit >> initmbr.txt
:RUNMBR
CLS
diskpart /s initmbr.txt
DEL initmbr.txt >nul
ECHO.
ECHO This drive is now prepared for WinNTSetup3 - MBR (BIOS)
ECHO.
ECHO The following drive letters have been assigned, and
ECHO will be automatically loaded into WinNTSetup3
ECHO.
ECHO Boot Drive----------: %BOOTDRV%
ECHO Installation Drive--: %DATADRV%
ECHO.
PAUSE
ECHO.
ECHO Please wait while WinNTSetup3 loads...
CD %~dp0
CD ..
START winntsetup_x64.exe /cfg:prep\template.ini
GOTO WINRE
:INITGPT
CLS
ECHO Prepare Hard Disk for WinNTSetup3 GPT (UEFI)
ECHO -----------------------------------------------------------
ECHO.
ECHO list disk >> list.txt
diskpart /s list.txt
DEL list.txt>nul
ECHO.
SET /p disk="Which disk number would you like to prepare? (e.g. 0): "
IF [%disk%] == [] GOTO INITGPT
ECHO.
ECHO --WARNING-- This will FORMAT the selected disk and ERASE ALL DATA
ECHO.
ECHO You selected disk ---^> %disk%
ECHO.
CHOICE /C YN /M "Is this correct "
IF %ERRORLEVEL% == 1 GOTO INITGPT2
CLS
ECHO Preperation Aborted, No changes have been made...
ECHO.
PAUSE
EXIT
:INITGPT2
SET BOOTDRV="S"
SET DATADRV="W"
ECHO select disk %disk% >> initgpt.txt
ECHO clean >> initgpt.txt
ECHO convert gpt >> initgpt.txt
rem == 1. System partition =========================
ECHO cre par efi size=100 >> initgpt.txt
rem ** NOTE: For Advanced Format 4Kn drives,
rem change this value to size = 260 **
ECHO for quick fs=fat32 label="System" >> initgpt.txt
ECHO assign letter %BOOTDRV% >> initgpt.txt
rem == 2. Microsoft Reserved (MSR) partition =======
ECHO cre par msr size=16 >> initgpt.txt
rem == 3. Windows partition ========================
rem == a. Create the Windows partition ==========
ECHO cre par pri >> initgpt.txt
rem == b. Create space for the recovery tools ===
ECHO shrink minimum=500 >> initgpt.txt
rem ** NOTE: Update this size to match the
rem size of the recovery tools
rem (winre.wim) **
rem == c. Prepare the Windows partition =========
ECHO for quick fs=ntfs label="Windows" >> initgpt.txt
ECHO assign letter %DATADRV% >> initgpt.txt
rem === 4. Recovery partition ======================
ECHO cre par pri >> initgpt.txt
ECHO for quick fs=ntfs label="Recovery" >> initgpt.txt
ECHO assign letter="R" >> initgpt.txt
ECHO set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac" >> initgpt.txt
ECHO gpt attributes=0x8000000000000001 >> initgpt.txt
ECHO exit >> initgpt.txt
:RUNGPT
CLS
diskpart /s initgpt.txt
DEL initgpt.txt >nul
ECHO.
ECHO This drive is now prepared for WinNTSetup3 - GPT (UEFI)
ECHO.
ECHO The following drive letters have been assigned, and
ECHO will be automatically loaded into WinNTSetup3
ECHO.
ECHO Boot Drive----------: %BOOTDRV%
ECHO Installation Drive--: %DATADRV%
ECHO.
PAUSE
ECHO.
ECHO Please wait while WinNTSetup3 loads...
CD %~dp0
CD ..
START winntsetup_x64.exe /cfg:prep\template.ini
ECHO.
:WINRE
ECHO Configure Windows Recovery Enviroment
ECHO -----------------------------------------------------------
ECHO.
CHOICE /C YN /M "Setup Windows Recovery Enviroment"
IF %ERRORLEVEL% == 1 GOTO INITWINRE
CLS
ECHO Configuration Aborted, No changes have been made...
ECHO.
PAUSE
EXIT
:INITWINRE
ECHO finding the Windows Drive
ECHO -------------------------
@IF EXIST C:\Windows SET windowsdrive=C:\
@IF EXIST D:\Windows SET windowsdrive=D:\
@IF EXIST E:\Windows SET windowsdrive=E:\
@IF EXIST W:\Windows SET windowsdrive=W:\
ECHO The Windows drive is %windowsdrive%
md R:\Recovery\WindowsRE
ECHO -------------------
ECHO Finding Winre.wim
@IF EXIST %windowsdrive%Recovery\WindowsRE\winre.wim SET recoveryfolder=%windowsdrive%Recovery\WindowsRE\
@IF EXIST %windowsdrive%Windows\System32\Recovery\winre.wim SET recoveryfolder=%windowsdrive%Windows\System32\Recovery\
ECHO -----------------------------------------------------------
ECHO copying Winre.wim
xcopy /h %recoveryfolder%Winre.wim R:\Recovery\WindowsRE\
ECHO -----------------------------------------------------------
ECHO == Register the location of the recovery tools ==
%windowsdrive%Windows\System32\Reagentc /Setreimage /Path R:\Recovery\WindowsRE /Target %windowsdrive%Windows
ECHO
ECHO == Verify the configuration status of the images. ==
%windowsdrive%Windows\System32\Reagentc /Info /Target %windowsdrive%Windows
ECHO (Note: Windows RE status may appear as Disabled, this is OK.)
ECHO -----------------------------------------------------------
CHOICE /C YN /M "Would You like To Exit"
:END