batch-filewinpe

Create .bat file for Windows ADK


As I need to build the WinPE multiple times per week (all with custom settings) I want to make a .bat file to speed this up. I can make different .bat files per option/customer.

I have made a file named amd64.bat with below:

@echo off

title WinPE building script

copype amd64 C:\winpe_amd64

Dism /Mount-Image /ImageFile:"C:\winpe_amd64\media\sources\boot.wim" /index:1 /MountDir:"C:\winpe_amd64\mount"
Dism /Add-Package /Image:"C:\winpe_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-WMI.cab"
Dism /Add-Package /Image:"C:\winpe_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-Scripting.cab"
[...]

I can run the amd64.bat file from the 'Deployment and Imaging Tools Environment' command line, but it only runs the first command, in this case: copype amd64 C:\winpe_amd64. After that no commands will be launched, even though the first command was successful.

I have been reading loads of articles, all telling me to use 'call' but this does not work either. Or I am using call wrongly.

Maybe there is a different way to do this or I miss some critical information. Any help is appreciated.

Some notes: If I have the color changed, this will work, same like the 'title' option. It simply runs the first command. The whole package is 30 commands long (this will grow with the growing amount of drivers to be added)

Thank you and Stay safe!


Solution

  • SOLVED!

    The .bat file had to look like this to make it work:

    @echo off
    title WinPE building script
    
    %SystemRoot%\System32\Dism.exe /cleanup-wim 
    call copype.cmd amd64 C:\winpe_amd64
    
    %SystemRoot%\System32\Dism.exe /Mount-Image /ImageFile:"C:\winpe_amd64\media\sources\boot.wim" /index:1 /MountDir:"C:\winpe_amd64\mount"
    %SystemRoot%\System32\Dism.exe /Add-Package /Image:"C:\winpe_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-WMI.cab"
    %SystemRoot%\System32\Dism.exe /Add-Package /Image:"C:\winpe_amd64\mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-Scripting.cab"
    
    pause
    

    So for me call copype.cmd amd64 C:\winpe_amd64 and adding %SystemRoot%\System32\Dism.exe instead of Dism did the trick.