The command used in the video:
- Build your PE filles. The path “C:\WinPE_ARM64” can be change to the path you want.
copype.cmd arm64 C:\WinPE_ARM64
3.Edit your “copype.cmd” and your “MakeWinPEMedia.cmd”
if you have the same path as the video, you can derectly copy the code.
Example Code
@echo off
setlocal
set TEMPL=media
set BOOTBINS=bootbins
set EXITCODE=0
set WIMMOUNTED=0
set WinPERoot=C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment
rem
rem Input validation
rem
if /i "%1"=="/?" goto usage
if /i "%1"=="" goto usage
if /i "%~2"=="" goto usage
if /i not "%3"=="" goto usage
rem
rem Set environment variables for use in the script
rem
set WINPE_ARCH=%1
set SOURCE=%WinPERoot%\%WINPE_ARCH%
set FWFILESROOT=C:\Oscdimg\arm64\Oscdimg
set DEST=%~2
set WIMSOURCEPATH=%SOURCE%\en-us\winpe.wim
rem
rem Validate input architecture
rem
rem If the source directory as per input architecture does not exist,
rem it means the architecture is not present
rem
if not exist "%SOURCE%" (
echo ERROR: The following processor architecture was not found: %WINPE_ARCH%.
goto fail
)
rem
rem Validate the boot app directory location
rem
rem If the input architecture is validated, this directory must exist
rem This check is only to be extra careful
rem
if not exist "%FWFILESROOT%" (
echo ERROR: The following path for firmware files was not found: "%FWFILESROOT%".
goto fail
)
rem
rem Make sure the appropriate winpe.wim is present
rem
if not exist "%WIMSOURCEPATH%" (
echo ERROR: WinPE WIM file does not exist: "%WIMSOURCEPATH%".
goto fail
)
rem
rem Make sure the destination directory does not exist
rem
if exist "%DEST%" (
echo ERROR: Destination directory exists: %2.
goto fail
)
mkdir "%DEST%"
if errorlevel 1 (
echo ERROR: Unable to create destination: %2.
goto fail
)
echo.
echo ===================================================
echo Creating Windows PE customization working directory
echo.
echo %DEST%
echo ===================================================
echo.
mkdir "%DEST%\%TEMPL%"
if errorlevel 1 (
echo ERROR: Unable to create directory: "%DEST%\%TEMPL%".
goto fail
)
mkdir "%DEST%\mount"
if errorlevel 1 (
echo ERROR: Unable to create directory: "%DEST%\mount".
goto fail
)
mkdir "%DEST%\%BOOTBINS%"
if errorlevel 1 (
echo ERROR: Unable to create directory: "%DEST%\%BOOTBINS%".
goto fail
)
echo Staging media files...
rem
rem Copy the boot files and WinPE WIM to the destination location
rem
xcopy /herky "%SOURCE%\Media" "%DEST%\%TEMPL%\" >NUL
if errorlevel 1 (
echo ERROR: Unable to copy boot files: "%SOURCE%\Media" to "%DEST%\%TEMPL%".
goto fail
)
mkdir "%DEST%\%TEMPL%\sources"
if errorlevel 1 (
echo ERROR: Unable to create directory: "%DEST%\%TEMPL%\sources".
goto fail
)
copy "%WIMSOURCEPATH%" "%DEST%\%TEMPL%\sources\boot.wim" >NUL
if errorlevel 1 (
echo ERROR: Unable to copy WinPE WIM: "%WIMSOURCEPATH%" to "%DEST%\%TEMPL%\sources\boot.wim".
goto fail
)
rem
rem Mount the WinPE WIM file
rem
echo Mounting "%DEST%\%TEMPL%\sources\boot.wim"
Dism.exe /Mount-Image /ImageFile:"%DEST%\%TEMPL%\sources\boot.wim" /Index:1 /MountDir:"%DEST%\mount" /ReadOnly >NUL
if errorlevel 1 (
echo ERROR: Failed to mount the WinPE WIM file. Check logs at %WINDIR%\Logs\DISM for more details.
goto fail
)
set WIMMOUNTED=1
echo Copying boot files from WIM...
rem
rem Copy both 2011 and 2023 signed boot managers for later use
rem
copy "%DEST%\mount\Windows\Boot\EFI\bootmgfw.efi" "%DEST%\%BOOTBINS%" >NUL
if errorlevel 1 (
echo ERROR: Unable to copy boot file: "bootmgfw.efi" to "%DEST%\%BOOTBINS%".
goto fail
)
copy "%DEST%\mount\Windows\Boot\EFI_EX\bootmgfw_EX.efi" "%DEST%\%BOOTBINS%" >NUL
if errorlevel 1 (
echo ERROR: Unable to copy boot file: "bootmgfw_EX.efi" to "%DEST%\%BOOTBINS%".
goto fail
)
rem
rem Copy the boot sector files to enable ISO creation and boot
rem
rem UEFI boot uses efisys.bin or efisys_EX.bin
rem BIOS boot uses etfsboot.com
rem
copy "%FWFILESROOT%\efisys.bin" "%DEST%\%BOOTBINS%" >NUL
if errorlevel 1 (
echo ERROR: Unable to copy boot sector file: "%FWFILESROOT%\efisys.bin" to "%DEST%\%BOOTBINS%".
goto fail
)
copy "%FWFILESROOT%\efisys_noprompt.bin" "%DEST%\%BOOTBINS%" >NUL
if errorlevel 1 (
echo ERROR: Unable to copy boot sector file: "%FWFILESROOT%\efisys_noprompt.bin" to "%DEST%\%BOOTBINS%".
goto fail
)
copy "%FWFILESROOT%\efisys.bin" "%DEST%\%BOOTBINS%" >NUL
if errorlevel 1 (
echo ERROR: Unable to copy boot sector file: "%FWFILESROOT%\efisys.bin" to "%DEST%\%BOOTBINS%".
goto fail
)
copy "%FWFILESROOT%\efisys_noprompt.bin" "%DEST%\%BOOTBINS%" >NUL
if errorlevel 1 (
echo ERROR: Unable to copy boot sector file: "%FWFILESROOT%\efisys_noprompt.bin" to "%DEST%\%BOOTBINS%".
goto fail
)
if not exist "%FWFILESROOT%\etfsboot.com" goto success
copy "%FWFILESROOT%\etfsboot.com" "%DEST%\%BOOTBINS%" >NUL
if errorlevel 1 (
echo ERROR: Unable to copy boot sector file: "%FWFILESROOT%\etfsboot.com" to "%DEST%\%BOOTBINS%".
goto fail
)
:success
set EXITCODE=0
cd /d "%~2"
goto cleanup
:usage
set EXITCODE=1
echo Creates working directories for WinPE image customization and media creation.
echo.
echo copype { amd64 ^| x86 ^| arm ^| arm64 } ^<workingDirectory^>
echo.
echo amd64 Copies amd64 boot files and WIM to ^<workingDirectory^>\media.
echo x86 Copies x86 boot files and WIM to ^<workingDirectory^>\media.
echo arm Copies arm boot files and WIM to ^<workingDirectory^>\media.
echo arm64 Copies arm64 boot files and WIM to ^<workingDirectory^>\media.
echo Note: ARM/ARM64 content may not be present in this ADK.
echo workingDirectory Creates the working directory at the specified location.
echo.
echo Example: copype amd64 C:\WinPE_amd64
goto cleanup
:fail
set EXITCODE=1
echo.
echo Failed to stage %DEST%!
echo.
goto cleanup
:cleanup
if %WIMMOUNTED% EQU 1 (
echo Unmounting "%DEST%\%TEMPL%\sources\boot.wim"
Dism.exe /Unmount-Image /MountDir:"%DEST%\mount" /Discard >NUL
if errorlevel 1 (
echo ERROR: "%DEST%\%TEMPL%\sources\boot.wim" still mounted!
set EXITCODE=1
)
)
if %EXITCODE% EQU 0 (
echo.
echo ===================================================
echo Successfully staged %DEST%
echo ===================================================
echo.
)
endlocal & exit /b %EXITCODE%
@echo off
setlocal
rem
rem Set variables for local use
rem
set TEMPL=media
set BOOTBINS=bootbins
set DISKPARTSCRIPT=%TMP%\UFDFormatDiskpartScript.txt
set EXITCODE=0
set BOOTEX=0
set FORCED=0
rem
rem Input validation
rem
if /i "%1"=="/?" goto usage
if /i "%1"=="" goto usage
if /i "%~2"=="" goto usage
if /i "%~3"=="" goto usage
if /i not "%1"=="/UFD" (
if /i not "%1"=="/ISO" goto usage
)
rem
rem Based on parameters input, assign local variables
rem
set WORKINGDIR=%~2
set DEST=%~3
if /i "%~2"=="/f" (
set FORCED=1
set WORKINGDIR=%~3
set DEST=%~4
if /i "%~5"=="/bootex" (
set BOOTEX=1
)
if /i not "%~6"=="" goto usage
) else (
if /i "%~4"=="/bootex" (
set BOOTEX=1
)
if /i not "%~5"=="" goto usage
)
rem
rem Make sure the working directory exists
rem
if not exist "%WORKINGDIR%" (
echo ERROR: Working directory does not exist: "%WORKINGDIR%".
goto fail
)
rem
rem Make sure the working directory is valid as per our requirements
rem
if not exist "%WORKINGDIR%\%TEMPL%" (
echo ERROR: Working directory is not valid: "%WORKINGDIR%".
goto fail
)
set BOOTMGRPATH=%WORKINGDIR%\%BOOTBINS%\bootmgfw.efi
if %BOOTEX% EQU 1 (
rem Use the 'Windows UEFI CA 2023' signed version
set BOOTMGRPATH=%WORKINGDIR%\%BOOTBINS%\bootmgfw_EX.efi
)
if exist "%WORKINGDIR%\%TEMPL%\EFI\BOOT\bootx64.efi" (
copy "%BOOTMGRPATH%" "%WORKINGDIR%\%TEMPL%\EFI\BOOT\bootx64.efi" >NUL
)
if exist "%WORKINGDIR%\%TEMPL%\EFI\BOOT\bootaa64.efi" (
copy "%BOOTMGRPATH%" "%WORKINGDIR%\%TEMPL%\EFI\BOOT\bootaa64.efi" >NUL
)
copy "%BOOTMGRPATH%" "%WORKINGDIR%\%TEMPL%\EFI\MICROSOFT\BOOT\bootmgfw.efi" >NUL
if not defined %TMP% (
set DISKPARTSCRIPT=.\UFDFormatDiskpartScript.txt
)
if /i "%1"=="/UFD" goto UFDWorker
if /i "%1"=="/ISO" goto ISOWorker
rem
rem UFD section of the script, for creating bootable WinPE UFD
rem
:UFDWorker
rem
rem Make sure the user has administrator privileges
rem These will be required to format the drive and set the boot code
rem
set ADMINTESTDIR=%WINDIR%\System32\Test_%RANDOM%
mkdir "%ADMINTESTDIR%" 2>NUL
if errorlevel 1 (
echo ERROR: You need to run this command with administrator privileges.
goto fail
) else (
rd /s /q "%ADMINTESTDIR%"
)
rem
rem Make sure the destination refers to a storage drive,
rem and is not any other type of path
rem
echo %DEST%| findstr /B /E /I "[A-Z]:" >NUL
if errorlevel 1 (
echo ERROR: Destination needs to be a disk drive, e.g F:.
goto fail
)
rem
rem Make sure the destination path exists
rem
if not exist "%DEST%" (
echo ERROR: Destination drive "%DEST%" does not exist.
goto fail
)
if %FORCED% EQU 1 goto UFDWorker_FormatUFD
rem
rem Confirm from the user that they want to format the drive
rem
echo WARNING, ALL DATA ON DISK DRIVE %DEST% WILL BE LOST!
choice /M "Proceed with Format "
if errorlevel 2 goto UFDWorker_NoFormatUFD
if errorlevel 1 goto UFDWorker_FormatUFD
:UFDWorker_NoFormatUFD
echo UFD %DEST% will not be formatted; exiting.
goto cleanup
:UFDWorker_FormatUFD
rem
rem Format the volume using diskpart, in FAT32 file system
rem
echo select volume=%DEST% > "%DISKPARTSCRIPT%"
echo format fs=fat32 label="WinPE" quick override>> "%DISKPARTSCRIPT%"
echo active >> "%DISKPARTSCRIPT%"
echo Formatting %DEST%...
echo.
diskpart /s "%DISKPARTSCRIPT%" >NUL
set DISKPARTERR=%ERRORLEVEL%
del /F /Q "%DISKPARTSCRIPT%"
if errorlevel 1 (
echo WARNING: Failed to delete temporary DiskPart script "%DISKPARTSCRIPT%".
)
if %DISKPARTERR% NEQ 0 (
echo ERROR: Failed to format "%DEST%"; DiskPart errorlevel %DISKPARTERR%.
goto fail
)
rem
rem Set the boot code on the volume using bootsect.exe
rem
echo Setting the boot code on %DEST%...
echo.
bootsect.exe /nt60 %DEST% /force /mbr >NUL
if errorlevel 1 (
echo ERROR: Failed to set the boot code on %DEST%.
goto fail
)
rem
rem We first decompress the source directory that we are copying from.
rem This is done to work around an issue with xcopy when working with
rem compressed NTFS source directory.
rem
rem Note that this command will not cause an error on file systems that
rem do not support compression - because we do not use /f.
rem
compact /u "%WORKINGDIR%\%TEMPL%" >NUL
if errorlevel 1 (
echo ERROR: Failed to decompress "%WORKINGDIR%\%TEMPL%".
goto fail
)
rem
rem Copy the media files from the user-specified working directory
rem
echo Copying files to %DEST%...
echo.
xcopy /herky "%WORKINGDIR%\%TEMPL%\*.*" "%DEST%\" >NUL
if errorlevel 1 (
echo ERROR: Failed to copy files to "%DEST%\".
goto fail
)
goto success
rem
rem ISO section of the script, for creating bootable ISO image
rem
:ISOWorker
rem
rem Make sure the destination refers to an ISO file, ending in .ISO
rem
echo %DEST%| findstr /E /I "\.iso" >NUL
if errorlevel 1 (
echo ERROR: Destination needs to be an .ISO file.
goto fail
)
if not exist "%DEST%" goto ISOWorker_OscdImgCommand
if %FORCED% EQU 1 goto ISOWorker_CleanDestinationFile
rem
rem Confirm from the user that they want to overwrite the existing ISO file
rem
choice /M "Destination file %DEST% exists, overwrite it "
if errorlevel 2 goto ISOWorker_DestinationFileExists
if errorlevel 1 goto ISOWorker_CleanDestinationFile
:ISOWorker_DestinationFileExists
echo Destination file %DEST% will not be overwritten; exiting.
goto cleanup
:ISOWorker_CleanDestinationFile
rem
rem Delete the existing ISO file
rem
del /F /Q "%DEST%"
if errorlevel 1 (
echo ERROR: Failed to delete "%DEST%".
goto fail
)
:ISOWorker_OscdImgCommand
rem
rem Set the correct boot argument based on availability of boot apps
rem
if %BOOTEX% EQU 1 (
set EFISYS=pEF,e,b"%WORKINGDIR%\%BOOTBINS%\efisys_EX.bin"
) else (
set EFISYS=pEF,e,b"%WORKINGDIR%\%BOOTBINS%\efisys.bin"
)
set BOOTDATA=1#%EFISYS%
if exist "%WORKINGDIR%\%BOOTBINS%\etfsboot.com" (
set BOOTDATA=2#p0,e,b"%WORKINGDIR%\%BOOTBINS%\etfsboot.com"#%EFISYS%
)
rem
rem Create the ISO file using the appropriate OSCDImg command
rem
echo Creating %DEST%...
echo.
C:\Oscdimg\arm64\Oscdimg\oscdimg -bootdata:%BOOTDATA% -u1 -udfver102 "%WORKINGDIR%\%TEMPL%" "%DEST%" >NUL
if errorlevel 1 (
echo ERROR: Failed to create "%DEST%" file.
goto fail
)
goto success
:success
set EXITCODE=0
echo.
echo Success
echo.
goto cleanup
:usage
set EXITCODE=1
echo Creates bootable WinPE USB flash drive or ISO file.
echo.
echo MakeWinPEMedia {/ufd ^| /iso} [/f] ^<workingDirectory^> ^<destination^> [/bootex]
echo.
echo /ufd Specifies a USB Flash Drive as the media type.
echo NOTE: THE USB FLASH DRIVE WILL BE FORMATTED.
echo /iso Specifies an ISO file (for CD or DVD) as the media type.
echo /f Suppresses prompting to confirm formatting the UFD
echo or overwriting existing ISO file.
echo workingDirectory Specifies the working directory created using copype.cmd
echo The contents of the ^<workingDirectory^>\media folder
echo will be copied to the UFD or ISO.
echo destination Specifies the UFD volume or .ISO path and file name.
echo /bootex Optional - specifies to use boot files signed with 'Windows UEFI CA 2023' certificate
echo.
echo Examples:
echo MakeWinPEMedia /UFD C:\WinPE_amd64 G:
echo MakeWinPEMedia /UFD /F C:\WinPE_amd64 H:
echo MakeWinPEMedia /ISO C:\WinPE_x86 C:\WinPE_x86\WinPE_x86.iso
echo MakeWinPEMedia /UFD C:\WinPE_amd64 F: /bootex
echo MakeWinPEMedia /ISO /f C:\WinPE_amd64 C:\WinPE_x86\WinPE_amd64.iso /bootex
goto cleanup
:fail
set EXITCODE=1
goto cleanup
:cleanup
endlocal & exit /b %EXITCODE%
4. add the software in the media/sources/boot.wim package with software like 7zip.
5. Make your ISO file. The first path “C:\WinPE_ARM64” is your PE files path and the second “C:\WinPE_ARM64\WinPE_ARM64.iso” is your ISO output path.
MakeWinPEMedia /ISO C:\WinPE_ARM64 C:\WinPE_ARM64\WinPE_ARM64.iso
6. Congratulate! You can boot your ISO file in VMs or flash ISO into USB.