Creating a dual-boot WinPE boot image (x86 and x64 support)

Discussion in 'Scripting' started by Chibi ANUBIS, Nov 6, 2019.

  1. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    1,235
    910
    60
    #1 Chibi ANUBIS, Nov 6, 2019
    Last edited: Jun 3, 2020
    Hello ! :)
    To create the boot image you need to have Windows ADK 10 installed.

    Script for create a WinPE (thanks to rpo) POST NUMBER
    French integration script and create a bootable media
    All languages integration script and create a bootable media
    REMEMBER : To reduce the size of the iso, just remove the extra packages they are not mandatory.


    Then creating the dual-boot boot image is quite straightforward and consists of the following steps:
    • Create the x86 boot image
    • Create the x64 boot image
    • Modify the BCD entry to contain both boot images
    • Create the ISO or USB stick
    • Optional : Change Keyboard Layout
    Create the x86 WinPE boot image
    1. On the machine with Windows ADK 10 installed, from the Start screen, launch Deployment and Imaging Tools Environment
    2. In the Command prompt that appears, run the following command:
      copype x86 C:\Tmp\WinPE_x86
    3. Using File Explorer, create the C:\Tmp\WinPE_Combined folder
    4. Navigate to the C:\Tmp\WinPE_x86 media folder and copy the content to the C:\Tmp\WinPE_Combined folder
    5. In the C:\Tmp\WinPE_Combined Sources folder, rename boot.wim to boot_x86.wim
    Create the x64 WinPE boot image
    1. Still in the Deployment and Imaging Tools Environment Command prompt run the following command:
      copype amd64 C:\Tmp\WinPE_x64
    2. Navigate to the C:\Tmp\WinPE_x64 media sources folder and copy the boot.wim file to the C:\Tmp\WinPE_Combined Sources folder
    3. In the C:\Tmp\WinPE_Combined Sources folder, rename boot.wim to boot_x64.wim
    [​IMG]
    Modify the BCD entry

    Run this script in Admin :
    Code:
    @ECHO OFF
    TITLE WinPE Dual Boot - Chibi ANUBIS
    COLOR F0
    pushd "%~dp0"
    SET BCDSTORE=C:\Tmp\WinPE_Combined\Boot\BCD
    SET WIM86=sources\boot_x86.wim
    SET WIM64=sources\boot_x64.wim
    if not exist %BCDSTORE% goto END
    bcdedit /store %BCDSTORE% /enum | find "osdevice" > GUID.txt
    For /F "tokens=2 delims={}" %%i in (GUID.txt) do (set _NEWGUID=%%i)
    bcdedit /store %BCDSTORE% /set {default} device ramdisk=[boot]\%WIM86%,{%_NEWGUID%}
    bcdedit /store %BCDSTORE% /set {default} osdevice ramdisk=[boot]\%WIM86%,{%_NEWGUID%}
    bcdedit /store %BCDSTORE% /set {default} description "WinPE x86"
    bcdedit /store %BCDSTORE% /copy {default} /d "WinPE x64" > GUID2.txt
    For /F "tokens=2 delims={}" %%i in (GUID2.txt) do (set _NEWGUID2=%%i)
    bcdedit /store %BCDSTORE% /set {%_NEWGUID2%} device ramdisk=[boot]\%WIM64%,{%_NEWGUID%}
    bcdedit /store %BCDSTORE% /set {%_NEWGUID2%} osdevice ramdisk=[boot]\%WIM64%,{%_NEWGUID%}
    bcdedit /store %BCDSTORE% /deletevalue {default} bootmenupolicy
    if exist GUID.txt DEL GUID.txt
    if exist GUID2.txt DEL GUID2.txt
    :END
    exit
    
    Create the bootable ISO or USB stick

    1. Rename the C:\Tmp\WinPE_Combined folder to C:\Tmp\Media (the MakeWinPEMedia.cmd is hardcoded to look for a folder named Media)
    2. If you want to create a bootable ISO, run the following command (the /f forces to overwrite if the ISO already exist, not required, but good to know about):
      MakeWinPEMedia /iso /f C:\Tmp C:\Tmp\WinPE_DualBoot.iso
    3. If you want to create a bootable USB, run the following command (the /f forces suppresses the warning about formatting the USB stick):
      MakeWinPEMedia /ufd /f C:\Tmp H:
    [​IMG]
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    1,235
    910
    60
    #2 Chibi ANUBIS, Nov 6, 2019
    Last edited: Nov 7, 2019
    (OP)
    Change the Keyboard Layout QWERTY by AZERTY ! :)

    Run this script in Admin :
    Code:
    @ECHO OFF
    TITLE Change Keyboard Layout - Chibi ANUBIS
    COLOR F0
    pushd "%~dp0"
    SET KL=fr-fr
    SET WIM86=C:\Tmp\WinPE_Combined\sources\boot_x86.wim
    SET WIM64=C:\Tmp\WinPE_Combined\sources\boot_x64.wim
    SET MOUNT=C:\Tmp\Mount
    if not exist %WIM86% goto ARCH64
    if not exist %MOUNT% mkdir %MOUNT%
    Dism /Mount-Wim /WimFile:%WIM86% /index:1 /MountDir:%MOUNT%
    Dism /image:%MOUNT% /Set-InputLocale:%KL%
    Dism /Unmount-Image /MountDir:%MOUNT% /Commit
    :ARCH64
    if not exist %WIM64% goto END
    if not exist %MOUNT% mkdir %MOUNT%
    Dism /Mount-Wim /WimFile:%WIM64% /index:1 /MountDir:%MOUNT%
    Dism /image:%MOUNT% /Set-InputLocale:%KL%
    Dism /Unmount-Image /MountDir:%MOUNT% /Commit
    :END
    exit
    
    Default Input Profiles (Input Locales) in Windows

    Is finish !! Your WinPE Keyboard Layout is now on AZERTY ! :clap:

    Alternatively, you can modify the registry with command line :
    Code:
    @ECHO OFF
    TITLE Change Keyboard Layout - Chibi ANUBIS
    COLOR F0
    pushd "%~dp0"
    SET WIM86=C:\Tmp\WinPE_Combined\sources\boot_x86.wim
    SET WIM64=C:\Tmp\WinPE_Combined\sources\boot_x64.wim
    SET MOUNT=C:\Tmp\Mount
    if not exist %WIM86% goto ARCH64
    if not exist %MOUNT% mkdir %MOUNT%
    Dism /Mount-Wim /WimFile:%WIM86% /index:1 /MountDir:%MOUNT%
    reg load HKLM\WinPE_SYSTEM %MOUNT%\Windows\System32\Config\SYSTEM
    reg add "HKLM\WinPE_SYSTEM\Keyboard Layout\Preload" /f /v 1 /t REG_SZ /d "0000040C"
    reg load HKLM\WinPE_DEFAULT %MOUNT%\Windows\System32\Config\DEFAULT
    reg add "HKLM\WinPE_DEFAULT\Keyboard Layout\Preload" /f /v 1 /t REG_SZ /d "0000040C"
    reg load HKLM\WinPE_NTUSER %MOUNT%\Users\Default\NTUSER.DAT
    reg add "HKLM\WinPE_NTUSER\Keyboard Layout\Preload" /f /v 1 /t REG_SZ /d "0000040C"
    reg unload HKLM\WinPE_SYSTEM
    reg unload HKLM\WinPE_DEFAULT
    reg unload HKLM\WinPE_NTUSER
    Dism /Unmount-Image /MountDir:%MOUNT% /Commit
    :ARCH64
    if not exist %WIM64% goto END
    if not exist %MOUNT% mkdir %MOUNT%
    Dism /Mount-Wim /WimFile:%WIM64% /index:1 /MountDir:%MOUNT%
    reg load HKLM\WinPE_SYSTEM %MOUNT%\Windows\System32\Config\SYSTEM
    reg add "HKLM\WinPE_SYSTEM\Keyboard Layout\Preload" /f /v 1 /t REG_SZ /d "0000040C"
    reg load HKLM\WinPE_DEFAULT %MOUNT%\Windows\System32\Config\DEFAULT
    reg add "HKLM\WinPE_DEFAULT\Keyboard Layout\Preload" /f /v 1 /t REG_SZ /d "0000040C"
    reg load HKLM\WinPE_NTUSER %MOUNT%\Users\Default\NTUSER.DAT
    reg add "HKLM\WinPE_NTUSER\Keyboard Layout\Preload" /f /v 1 /t REG_SZ /d "0000040C"
    reg unload HKLM\WinPE_SYSTEM
    reg unload HKLM\WinPE_DEFAULT
    reg unload HKLM\WinPE_NTUSER
    Dism /Unmount-Image /MountDir:%MOUNT% /Commit
    :END
    exit
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. coleoptere2007

    coleoptere2007 MDL Guru

    Apr 8, 2008
    3,313
    1,938
    120
    bookmarked for future use. Thx for this
     
  4. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,440
    1,420
    60
    #4 rpo, Nov 6, 2019
    Last edited: Nov 16, 2019
    Following is the script i use to create a localized French dual-boot WinPE boot image (x86 and x64 support). It asks for the path where to generate the iso image. The us language pack is suppressed. Some supplementary packages are added.
    Code:
    @echo off
    chcp 1252 >nul 2>&1
    :AskPath
    set /p DirWinPEISO=Chemin du fichier WinPE10.iso ? :^>
    if "%DirWinPEISO:~-1%"=="\" set "DirWinPEISO=%DirWinPEISO:~0,-1%"
    if not exist "%DirWinPEISO%" (
        echo Le répertoire %DirWinPEISO% est inaccessible
        goto :AskPath  
    )
    set "WinPEISO=%DirWinPEISO%\WinPE10.iso"
    set DirWinPEISO=
    @cls
    set "target=%temp%\WinPE10"
    REM Sets the OS architecture
    for /f "tokens=2 delims==" %%a in ('wmic cpu get AddressWidth /value') do (set arch=%%a)
    if "%arch%"=="32" (set "arch=x86") else (set "arch=amd64")
    REM Query the 32-bit and 64-bit Registry hive for KitsRoot
    SET regKeyPathFound=1
    SET wowRegKeyPathFound=1
    SET KitsRootRegValueName=KitsRoot10
    REG QUERY "HKLM\Software\Wow6432Node\Microsoft\Windows Kits\Installed Roots" /v %KitsRootRegValueName% 1>NUL 2>NUL || SET wowRegKeyPathFound=0
    REG QUERY "HKLM\Software\Microsoft\Windows Kits\Installed Roots" /v %KitsRootRegValueName% 1>NUL 2>NUL || SET regKeyPathFound=0
    if %wowRegKeyPathFound% EQU 0 (
      if %regKeyPathFound% EQU 0 (
        @echo Windows Kits n'est pas installé - Fin du traitement.
        pause
        goto :EOF
      ) else (
        SET regKeyPath=HKLM\Software\Microsoft\Windows Kits\Installed Roots
      )
    ) else (
        SET regKeyPath=HKLM\Software\Wow6432Node\Microsoft\Windows Kits\Installed Roots
    )
    FOR /F "skip=2 tokens=2*" %%i IN ('REG QUERY "%regKeyPath%" /v %KitsRootRegValueName%') DO (SET KitsRoot=%%j)
    SET "DandIRoot=%KitsRoot%Assessment and Deployment Kit\Deployment Tools"
    SET "WinPERoot=%KitsRoot%Assessment and Deployment Kit\Windows Preinstallation Environment"
    SET "OSCDImg=%DandIRoot%\%arch%\Oscdimg\Oscdimg.exe"
    ::
    rd /s /q "%target%" >nul 2>&1
    if exist "%target%" (echo "%target%" toujours présent - traitement abandonné & pause & exit /b)
    md "%target%"
    :: media : le WinPE au complet, prêt à être transformé en image ISO ou à mettre sur clé USB
    md "%target%\media"
    :: mount : dossier vide au départ, peut être utilisé comme point de montage pour l'image WIM du Live Windows, par exemple pour modifier le Live
    md "%target%\mount"
    :: fwfiles : contient les secteurs de boot CD/DVD pour BIOS et UEFI
    md "%target%\fwfiles"
    md "%target%\media\sources"
    md "%target%\media\Boot"
    md "%target%\media\Boot\en-us"
    md "%target%\media\Boot\fr-fr"
    md "%target%\media\Boot\Fonts"
    md "%target%\media\Boot\Resources"
    md "%target%\media\EFI"
    md "%target%\media\EFI\Boot"
    md "%target%\media\EFI\Boot\en-us"
    md "%target%\media\EFI\Boot\fr-fr"
    md "%target%\media\EFI\Microsoft"
    md "%target%\media\EFI\Microsoft\Boot"
    md "%target%\media\EFI\Microsoft\Boot\en-us"
    md "%target%\media\EFI\Microsoft\Boot\fr-fr"
    md "%target%\media\EFI\Microsoft\Boot\Fonts"
    md "%target%\media\EFI\Microsoft\Boot\Resources"
    ::
    copy "%WinPERoot%\x86\media\boot\*.*" "%target%\media\boot\"
    copy "%WinPERoot%\x86\media\boot\en-us\*.*" "%target%\media\boot\en-us\"
    copy "%WinPERoot%\x86\media\boot\fr-fr\*.*" "%target%\media\boot\fr-fr\"
    copy "%WinPERoot%\x86\media\boot\Fonts\*.*" "%target%\media\boot\Fonts\"
    copy "%WinPERoot%\x86\media\boot\Resources\*.*" "%target%\media\boot\Resources\"
    copy "%WinPERoot%\amd64\media\efi\boot\*.*" "%target%\media\efi\boot\"
    copy "%WinPERoot%\amd64\media\efi\boot\en-us\*.*" "%target%\media\efi\boot\en-us\"
    copy "%WinPERoot%\amd64\media\efi\boot\fr-fr\*.*" "%target%\media\efi\boot\fr-fr\" >nul 2>&1
    copy "%WinPERoot%\amd64\media\efi\microsoft\boot\*.*" "%target%\media\efi\microsoft\boot\"
    copy "%WinPERoot%\amd64\media\efi\microsoft\boot\en-us\*.*" "%target%\media\efi\microsoft\boot\en-us\"
    copy "%WinPERoot%\amd64\media\efi\microsoft\boot\fr-fr\*.*" "%target%\media\efi\microsoft\boot\fr-fr\"
    copy "%WinPERoot%\amd64\media\efi\microsoft\boot\fonts\*.*" "%target%\media\efi\microsoft\boot\fonts\"
    copy "%WinPERoot%\amd64\media\efi\microsoft\boot\resources\*.*" "%target%\media\efi\microsoft\boot\resources\"
    ::
    copy "%WinPERoot%\amd64\media\*.*" "%target%\media\"
    ::
    copy "%DandIroot%\amd64\Oscdimg\efisys.bin" "%target%\fwfiles\"
    copy "%DandIroot%\amd64\Oscdimg\efisys_noprompt.bin" "%target%\fwfiles\"
    copy "%DandIroot%\amd64\Oscdimg\etfsboot.com" "%target%\fwfiles\"
    ::
    echo.
    echo ************************************************************
    echo * Créer Boot.wim 32 bits                                   *
    echo ************************************************************
    echo.
    call :processwinpe x86
    ::
    echo.
    echo ************************************************************
    echo * Créer Boot.wim 64 bits                                   *
    echo ************************************************************
    echo.
    call :processwinpe amd64
    ::
    echo.
    echo ************************************************************
    echo * Modifier le BCD de façon à contenir les deux Boot.wim    *
    echo ************************************************************
    echo.
    echo BCD Bios pour x86 et amd64
    echo.
    set bcdstore=%target%\media\Boot\BCD
    :: bcdedit /store "%bcdstore%" /set {bootmgr} locale fr-FR
    bcdedit /store "%bcdstore%" /set {bootmgr} displaybootmenu yes
    ::    Get ramdisk guid
    for /f "tokens=2 delims=," %%A in ('bcdedit /store "%bcdstore%" /enum ^| find /i "osdevice"') do set ramdiskguid=%%A
    :: Modify the x86 boot entry
    bcdedit /store "%bcdstore%" /set {default} device ramdisk=[boot]\sources\boot_x86.wim,%ramdiskguid%
    bcdedit /store "%bcdstore%" /set {default} osdevice ramdisk=[boot]\sources\boot_x86.wim,%ramdiskguid%
    bcdedit /store "%bcdstore%" /set {default} description "WinPE 10 x86 bios"
    bcdedit /store "%bcdstore%" /set {default} locale fr-FR
    bcdedit /store "%bcdstore%" /deletevalue {default} bootmenupolicy
    ::    Create a x64 boot entry by making a copy of the x86 entry
    for /f "tokens=7 delims=. " %%A in ('bcdedit /store "%bcdstore%" /copy {default} /d "WinPE 10 x64 bios"') do set x64guid=%%A
    bcdedit /store "%bcdstore%" /set %x64guid% device ramdisk=[boot]\sources\boot_x64.wim,%ramdiskguid%
    bcdedit /store "%bcdstore%" /set %x64guid% osdevice ramdisk=[boot]\sources\boot_x64.wim,%ramdiskguid%
    del /A "%target%\media\Boot\BCD.log?"
    :: efi
    echo.
    echo BCD EFI pour amd64
    echo.
    set bcdstore=%target%\media\EFI\Microsoft\Boot\BCD
    :: bcdedit /store "%bcdstore%" /set {bootmgr} locale fr-FR
    bcdedit /store "%bcdstore%" /set {bootmgr} displaybootmenu yes
    ::    Get ramdisk guid
    for /f "tokens=2 delims=," %%A in ('bcdedit /store "%bcdstore%" /enum ^| find /i "osdevice"') do set ramdiskguid=%%A
    :: Modify the x64 boot entry
    bcdedit /store "%bcdstore%" /set {default} device ramdisk=[boot]\sources\boot_x64.wim,%ramdiskguid%
    bcdedit /store "%bcdstore%" /set {default} osdevice ramdisk=[boot]\sources\boot_x64.wim,%ramdiskguid%
    bcdedit /store "%bcdstore%" /set {default} description "WinPE 10 x64 efi"
    bcdedit /store "%bcdstore%" /set {default} locale fr-FR
    bcdedit /store "%bcdstore%" /deletevalue {default} bootmenupolicy
    del /A "%target%\media\EFI\Microsoft\Boot\BCD.log?"
    ::
    echo.
    echo ************************************************************
    Echo * Créer l'image iso                                        *
    echo ************************************************************
    echo.
    ::    Boot possible en BIOS (x86 et x6 et UEFI (X64 uniquement)
    if exist %WinPEISO% del %WinPEISO%
    "%oscdimg%" -bootdata:2#p0,e,b"%target%\fwfiles\etfsboot.com"#pEF,e,b"%target%\fwfiles\efisys_noprompt.bin" -h -u2 -m -o -lWinPE10 "%target%\media" "%WinPEISO%"
    ::
    goto :term
    ::
    :processwinpe
    set "arch=%1"
    echo.
    echo Monter l'image boot.wim
    copy "%WinPERoot%\%arch%\en-us\winpe.wim" "%target%\media\sources\boot.wim"
    dism /Mount-Image /ImageFile:"%target%\media\sources\boot.wim" /index:1 /MountDir:"%target%\mount"
    echo.
    echo Chercher le nom du pack de langue anglais
    for /f "tokens=4" %%a in ('dism /english /Image:"%target%\mount" /Get-Packages ^| findstr /i "LanguagePack"') do set langpkg=%%a
    echo.
    echo Ajouter le pack de langue français
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\fr-fr\lp.cab"
    Dism  /Image:"%target%\mount" /Set-AllIntl:fr-FR
    echo.
    echo Supprimer le pack de langue us
    dism /Image:"%target%\mount" /Remove-Package /PackageName:%langpkg%
    echo.
    echo Ajout de packs
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\WinPE-Scripting.cab"
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\WinPE-HTA.cab"
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\WinPE-WMI.cab"
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\WinPE-NetFx.cab"
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\WinPE-PowerShell.cab"
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\WinPE-DismCmdlets.cab"
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\WinPE-StorageWMI.cab"
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\fr-fr\WinPE-Scripting_fr-fr.cab"
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\fr-fr\WinPE-HTA_fr-fr.cab"
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\fr-fr\WinPE-WMI_fr-fr.cab"
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\fr-fr\WinPE-NetFx_fr-fr.cab"
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\fr-fr\WinPE-PowerShell_fr-fr.cab"
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\fr-fr\WinPE-DismCmdlets_fr-fr.cab"
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\fr-fr\WinPE-StorageWMI_fr-fr.cab"
    echo.
    echo Démonter l'image
    dism /Unmount-Image /MountDir:"%target%\mount" /commit
    echo.
    dism /export-image /sourceimagefile:"%target%\media\sources\boot.wim" /sourceindex:1 /DestinationImageFile:"%target%\media\sources\boot_x%arch:~-2%.wim"
    del "%target%\media\sources\boot.wim"
    goto :eof
    :term
    echo Fin du traitement
    chcp 850 >nul 2>&1
    

    Edit : this script is now superseded by the script in post #13
     
  5. Tiger-1

    Tiger-1 MDL Guru

    Oct 18, 2014
    7,897
    10,733
    240
    very good job, thanks for share
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    1,235
    910
    60
    #6 Chibi ANUBIS, Nov 6, 2019
    Last edited: Nov 6, 2019
    (OP)
    I test your script now :)

    Integration (copy your script in cmd file and run in Admin) = OK

    The iso size is 787 Mb, is not possible to put in a CD :(

    No possible to compress with Imagex
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,440
    1,420
    60
    Who uses in 2019 a boot cd?
    To reduce the size of the iso, just remove the extra packages they are not mandatory.
    You could also burn a dvd.
     
  8. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    1,235
    910
    60
    #8 Chibi ANUBIS, Nov 6, 2019
    Last edited: Nov 6, 2019
    (OP)
    A old cumputer boot again on a CD ;)

    I add the link to your script to my first OP
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,962
    904
    60
    Why don't you also mod the EFI\\Microsoft\Boot\BCD to point to boot_x64.wim? You could then boot in UEFI mode as well...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    1,235
    910
    60
    Yes you can add this also :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. coleoptere2007

    coleoptere2007 MDL Guru

    Apr 8, 2008
    3,313
    1,938
    120
    @Chibi ANUBIS ADK is not enough you have to download WinPE addons or the command copype is not recognized
     
  12. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    1,235
    910
    60
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,440
    1,420
    60
    This is an update of post #4
    Code:
    @set "WinPE=WinPE 10"
    @echo off
    echo The workingdirectory is %SystemDrive%\%WinPE%
    echo The iso name is %Winpe%; location is workingdirectory %SystemDrive%\%WinPE%
    for /f "tokens=3 delims=: " %%a in ('dism /online /english /get-intl ^| findstr /I "System locale"') do set "lang=%%a"
    echo The Winpe language %lang% is the same of the System locale. Can be changed with set "lang=xx-XX" 
    echo To include extra packages, uncomment the lines call :AddPackage package name
    rem set "lang=en-US"    &rem language can be changed here
    echo %WinPE% generated for %lang% language
    call "%ProgramFiles(x86)%\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\DandISetEnv.bat"
    set "target=%SystemDrive%\%WinPE%" & Rem Establish workingdirectory
    rem chcp 1252 >nul 2>&1 & rem chcp 1252 causes E:|findstr /B /E /I "[A-Z]:" to hang !
    ::
    rd /s /q "%target%" >nul 2>&1
    rem Make sure the destination directory does not exist
    if exist "%target%" (
      echo ERROR: "%target%" destination directory exists - abort. & pause & exit /b)
    robocopy "%WinPERoot%\x86\media" "%target%\media"
    robocopy "%WinPERoot%\x86\media\boot" "%target%\media\boot"
    robocopy "%WinPERoot%\x86\media\boot\en-us" "%target%\media\boot\en-us"
    robocopy "%WinPERoot%\x86\media\boot\%lang%" "%target%\media\boot\%lang%"
    robocopy "%WinPERoot%\x86\media\boot\Fonts" "%target%\media\boot\fonts"
    robocopy "%WinPERoot%\x86\media\boot\Resources" "%target%\media\boot\Resources"
    robocopy "%WinPERoot%\x86\media\efi\boot" "%target%\media\efi\boot"
    robocopy "%WinPERoot%\x86\media\efi\microsoft\boot" "%target%\media\efi\microsoft\boot"
    ren      "%target%\media\EFI\Microsoft\boot\memtest.efi" memtest_x86.efi
    robocopy "%WinPERoot%\amd64\media" "%target%\media"
    robocopy "%WinPERoot%\amd64\media\efi\boot" "%target%\media\efi\boot"
    robocopy "%WinPERoot%\amd64\media\efi\boot\en-us" "%target%\media\efi\boot\en-us"
    robocopy "%WinPERoot%\amd64\media\efi\boot\%lang%" "%target%\media\efi\boot\%lang%" >nul 2>&1
    robocopy "%WinPERoot%\amd64\media\efi\microsoft\boot" "%target%\media\efi\microsoft\boot"
    robocopy "%WinPERoot%\amd64\media\efi\microsoft\boot\en-us" "%target%\media\efi\microsoft\boot\en-us"
    robocopy "%WinPERoot%\amd64\media\efi\microsoft\boot\%lang%" "%target%\media\efi\microsoft\boot\%lang%"
    robocopy "%WinPERoot%\amd64\media\efi\microsoft\boot\fonts" "%target%\media\efi\microsoft\boot\fonts"
    robocopy "%WinPERoot%\amd64\media\efi\microsoft\boot\resources" "%target%\media\efi\microsoft\boot\resources"
    ::
    md "%target%\media\sources"
    ::
    md "%target%\mount"
    ::
    echo.
    echo ************************************************************
    echo * Create Boot.wim 32 bits                                  *
    echo ************************************************************
    echo.
    call :processwinpe x86
    ::
    echo.
    echo ************************************************************
    echo * Create Boot.wim 64 bits                                  *
    echo ************************************************************
    echo.
    call :processwinpe amd64
    ::
    echo.
    echo.
    echo ***************************************************************
    echo * Modify BCD so it contains bothboot_x86.wim and boot_x64.wim *
    echo ***************************************************************
    echo.
    echo BCD Bios for x64 and x86
    echo.
    set "bcdstore=%target%\media\Boot\BCD"
    bcdedit /store "%bcdstore%" /set {bootmgr} displaybootmenu yes
    bcdedit /store "%bcdstore%" /set {bootmgr} locale %lang%
    bcdedit /store "%bcdstore%" /deletevalue {bootmgr} toolsdisplayorder
    rem    Get ramdisk guid
    for /f "tokens=2 delims=," %%A in ('bcdedit /store "%bcdstore%" /enum ^| find /i "osdevice"') do set ramdiskguid=%%A
    rem Modify the x64 boot entry
    bcdedit /store "%bcdstore%" /set {default} device ramdisk=[boot]\sources\boot_x64.wim,%ramdiskguid%
    bcdedit /store "%bcdstore%" /set {default} osdevice ramdisk=[boot]\sources\boot_x64.wim,%ramdiskguid%
    bcdedit /store "%bcdstore%" /set {default} description "%WinPE% x64 bios"
    bcdedit /store "%bcdstore%" /set {default} locale %lang%
    bcdedit /store "%bcdstore%" /set {default} bootmenupolicy Legacy
    rem    Create a x86 boot entry by making a copy of the x64 entry
    for /f "tokens=7 delims=. " %%A in ('bcdedit /store "%bcdstore%" /copy {default} /d "%WinPE% x86 bios"') do set x86guid=%%A
    bcdedit /store "%bcdstore%" /set %x86guid% device ramdisk=[boot]\sources\boot_x86.wim,%ramdiskguid%
    bcdedit /store "%bcdstore%" /set %x86guid% osdevice ramdisk=[boot]\sources\boot_x86.wim,%ramdiskguid%
    rem Create a boot entry for memory test
    for /f "tokens=2 delims={}" %%a in ('bcdedit /store "%bcdstore%" /create /d "Memory Test" /application osloader') do set bcdentry={%%a}
    bcdedit /store "%bcdstore%" /set %bcdentry% device boot
    bcdedit /store "%bcdstore%" /set %bcdentry% path \boot\memtest.exe
    bcdedit /store "%bcdstore%" /set %bcdentry% locale %lang%
    bcdedit /store "%bcdstore%" /set %bcdentry% nointegritychecks Yes
    bcdedit /store "%bcdstore%" /displayorder %bcdentry% /addlast
    del /A "%target%\media\Boot\BCD.log?"
    rem efi
    echo.
    echo BCD EFI for x64 and x86
    echo.
    set "bcdstore=%target%\media\EFI\Microsoft\Boot\BCD"
    rem bcdedit /store "%bcdstore%" /set {bootmgr} locale %lang%
    bcdedit /store "%bcdstore%" /set {bootmgr} displaybootmenu yes
    bcdedit /store "%bcdstore%" /set {bootmgr} locale %lang%
    bcdedit /store "%bcdstore%" /deletevalue {bootmgr} toolsdisplayorder
    rem    Get ramdisk guid
    for /f "tokens=2 delims=," %%A in ('bcdedit /store "%bcdstore%" /enum ^| find /i "osdevice"') do set ramdiskguid=%%A
    rem Modify the x64 boot entry
    bcdedit /store "%bcdstore%" /set {default} device ramdisk=[boot]\sources\boot_x64.wim,%ramdiskguid%
    bcdedit /store "%bcdstore%" /set {default} osdevice ramdisk=[boot]\sources\boot_x64.wim,%ramdiskguid%
    bcdedit /store "%bcdstore%" /set {default} description "%WinPE% x64 efi"
    bcdedit /store "%bcdstore%" /set {default} locale %lang%
    bcdedit /store "%bcdstore%" /set {default} bootmenupolicy Legacy
    rem Create a boot entry for memory test
    for /f "tokens=2 delims={}" %%a in ('bcdedit /store "%bcdstore%" /create /d "Memory Test EFI x64" /application osloader') do set bcdentry={%%a}
    bcdedit /store "%bcdstore%" /set %bcdentry% device boot
    bcdedit /store "%bcdstore%" /set %bcdentry% path \EFI\Microsoft\Boot\memtest.efi
    bcdedit /store "%bcdstore%" /set %bcdentry% locale %lang%
    bcdedit /store "%bcdstore%" /set %bcdentry% nointegritychecks Yes
    bcdedit /store "%bcdstore%" /displayorder %bcdentry% /addlast
    rem    Create a x86 boot entry by making a copy of the x64 entry
    for /f "tokens=7 delims=. " %%A in ('bcdedit /store "%bcdstore%" /copy {default} /d "WinPE 10 x86 bios"') do set x86guid=%%A
    bcdedit /store "%bcdstore%" /set %x86guid% device ramdisk=[boot]\sources\boot_x86.wim,%ramdiskguid%
    bcdedit /store "%bcdstore%" /set %x86guid% osdevice ramdisk=[boot]\sources\boot_x86.wim,%ramdiskguid%
    rem Create a boot entry for memory test
    for /f "tokens=2 delims={}" %%a in ('bcdedit /store "%bcdstore%" /create /d "Memory Test EFI x86" /application osloader') do set bcdentry={%%a}
    bcdedit /store "%bcdstore%" /set %bcdentry% device boot
    bcdedit /store "%bcdstore%" /set %bcdentry% path \EFI\Microsoft\Boot\memtest_x86.efi
    bcdedit /store "%bcdstore%" /set %bcdentry% locale %lang%
    bcdedit /store "%bcdstore%" /set %bcdentry% nointegritychecks Yes
    bcdedit /store "%bcdstore%" /displayorder %bcdentry% /addlast
    del /A "%target%\media\EFI\Microsoft\Boot\BCD.log?"
    rem
    echo.
    echo.
    echo ************************************************************
    Echo * Create iso image                                         *
    echo ************************************************************
    echo.
    ::    Boot possible en BIOS (x86 et x6 et UEFI (X64 uniquement)
    oscdimg.exe -bootdata:2#p0,e,b"%OSCDImgRoot%\etfsboot.com"#pEF,e,b"%OSCDImgRoot%\efisys_noprompt.bin" -h -u2 -m -o -l"%WinPE%" "%target%\media" "%target%\%WinPE%.iso"
    ::
    echo.
    echo ************************************************************
    Echo * Create optional USB key                                  *
    echo ************************************************************
    echo.
    set /p Driveletter=If you want to create a USB key, enter its drive letter ? :^>
    if "%Driveletter%X"=="X" goto USB_End
    if "%Driveletter:~-1%"==":" set "Driveletter=%Driveletter:~0,-1%"
    set "Driveletter=%Driveletter%:"
    echo %Driveletter%| findstr /B /E /I "[A-Z]:" >NUL
    if errorlevel 1 goto USB_End
    (
    echo select volume=%Driveletter%
    echo format fs=fat32 label="WinPE" quick
    echo active
    )|diskpart
    bootsect.exe /nt60 %Driveletter% /force /mbr >NUL
    robocopy "%target%\media" %Driveletter% /e
    :USB_End
    goto :term
    ::
    echo.
    echo ************************************************************
    Echo * Add package to boot.wim                                  *
    echo ************************************************************
    echo.
    :AddPackage
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\%1.cab"
    if /i not %lang%==en-us (
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\%lang%\%1_%lang%.cab")
    exit /b
    echo.
    echo ************************************************************
    Echo * Update boot.wim                                          *
    echo ************************************************************
    echo.
    :processwinpe
    set "arch=%1"
    echo.
    echo Mount boot.wim image
    copy "%WinPERoot%\%arch%\en-us\winpe.wim" "%target%\media\sources\boot.wim"
    dism /Mount-Image /ImageFile:"%target%\media\sources\boot.wim" /index:1 /MountDir:"%target%\mount"
    echo.
    if /I %lang%==en-US goto EndLang
    echo Get the en-US language pack name
    for /f "tokens=4" %%a in ('dism /english /Image:"%target%\mount" /Get-Packages ^| findstr /i "LanguagePack"') do set langpkg=%%a
    echo.
    echo Add %lang% language pack
    dism /Image:"%target%\mount" /Add-Package /PackagePath:"%WinPERoot%\%arch%\WinPE_OCs\%lang%\lp.cab"
    Dism  /Image:"%target%\mount" /Set-AllIntl:%lang%
    echo.
    echo Remove en-US language pack
    dism /Image:"%target%\mount" /Remove-Package /PackageName:%langpkg%
    :EndLang
    echo.
    echo Add packs
    rem call :AddPackage WinPE-Scripting
    rem call :AddPackage WinPE-HTA
    rem call :AddPackage WinPE-WMI
    rem call :AddPackage WinPE-NetFx
    rem call :AddPackage WinPE-PowerShell
    rem call :AddPackage WinPE-DismCmdlets
    rem call :AddPackage WinPE-StorageWMI
    echo.
    echo Unmount the image
    dism /Unmount-Image /MountDir:"%target%\mount" /commit
    echo.
    dism /export-image /sourceimagefile:"%target%\media\sources\boot.wim" /sourceindex:1 /DestinationImageFile:"%target%\media\sources\boot_x%arch:~-2%.wim" /Compress:max
    del "%target%\media\sources\boot.wim"
    exit /b
    ::
    echo.
    echo ************************************************************
    Echo * Exit                                                     *
    echo ************************************************************
    echo.
    :term
    rd /s /q "%target%\media"
    rd /s /q "%target%\mount"   
    echo End of process
    rem chcp 850 >nul 2>&1
    pause
    

    Tested with :
    Legacy bios mbr 32 and 64 bits :USB and CD/DVD ok
    UEFI : 64 bits : USB and CD/DVD ok I have no 32 bits UEFI platform to test
     
  14. Chibi ANUBIS

    Chibi ANUBIS MDL Chibi Developer

    Apr 28, 2014
    1,235
    910
    60
    #14 Chibi ANUBIS, Nov 16, 2019
    Last edited: Nov 16, 2019
    (OP)
    Thanks, is for all languages :)

    I updated my first OP !
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...