How to run copype.cmd for WinPE from Batch File

Mark Deven

I'm writing a tool that sets up a WinPE Drive for you, and I have been calling DISM commands from an admin batch file. However, I cannot figure out how to run the copype command to set up the drive initially.

"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\copype.cmd" is where the copype tool is located but when calling it with dism with this command: Dism "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\copype.cmd" amd64 C:\WinPE_amd64 it responds that Dism doesn't recognise the command-line option "copype.cmd" If I try running the file directly from a command prompt, it says it cannot find the amd64 infrastructure. The only way I can get it to start is if I run an administrator Deployment and Imaging Tools Environment and run the copype command. There must be a way to do this, but I cant figure out how.

Mark Deven

Turns out the Windows ADK Copype has been a bit broken since Windows 8. It's missing some variable. If you put this in your batch file you can use call :copype to call commands to it:

:copype
setlocal

set TEMPL=media
set FWFILES=fwfiles

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=C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\%WINPE_ARCH%
set FWFILESROOT=C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\%WINPE_ARCH%\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%.
  exit /b 1
)

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%".
  exit /b 1
)

rem
rem Make sure the appropriate winpe.wim is present
rem
if not exist "%WIMSOURCEPATH%" (
  echo ERROR: WinPE WIM file does not exist: "%WIMSOURCEPATH%".
  exit /b 1
)

rem
rem Make sure the destination directory does not exist
rem
if exist "%DEST%" (
  echo ERROR: Destination directory exists: %2.
  exit /b 1
)

mkdir "%DEST%"
if errorlevel 1 (
  echo ERROR: Unable to create destination: %2.
  exit /b 1
)

echo.
echo ===================================================
echo Creating Windows PE customization working directory
echo.
echo     %DEST%
echo ===================================================
echo.

mkdir "%DEST%\%TEMPL%"
if errorlevel 1 goto :FAIL
mkdir "%DEST%\mount"
if errorlevel 1 goto :FAIL
mkdir "%DEST%\%FWFILES%"
if errorlevel 1 goto :FAIL

rem
rem Copy the boot files and WinPE WIM to the destination location
rem
xcopy /cherky "%SOURCE%\Media" "%DEST%\%TEMPL%\"
if errorlevel 1 goto :FAIL
mkdir "%DEST%\%TEMPL%\sources"
if errorlevel 1 goto :FAIL
copy "%WIMSOURCEPATH%" "%DEST%\%TEMPL%\sources\boot.wim"
if errorlevel 1 goto :FAIL

rem
rem Copy the boot apps to enable ISO boot
rem
rem  UEFI boot uses efisys.bin
rem  BIOS boot uses etfsboot.com
rem
copy "%FWFILESROOT%\efisys.bin" "%DEST%\%FWFILES%"
if errorlevel 1 goto :FAIL
if exist "%FWFILESROOT%\etfsboot.com" (
  copy "%FWFILESROOT%\etfsboot.com" "%DEST%\%FWFILES%"
  if errorlevel 1 goto :FAIL
)

endlocal
echo.
echo Success
echo.

cd /d "%~2"

goto :EOF

:usage
echo Creates working directories for WinPE image customization and media creation.
echo.
echo copype { amd64 ^| x86 ^| arm } ^<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                    Note: ARM 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 :EOF

:FAIL
echo ERROR: Failed to create working directory.
set EROP=YEs
exit /b 1
Rem CopyPE created by Microsoft and Edited by Lucas Elliott and wjsorensen on technet
::------------------------ END --------------------------

For Anyone using Windows 8, you can see their solution here: https://social.technet.microsoft.com/Forums/ie/en-US/1155d38c-e7fd-4b4f-a31c-26875d4f47a7/windows-pe-error-using-windows-8-adk?forum=w8itproinstall

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to run a PowerShell script from a batch file

From Java

In a CMD batch file, can I determine if it was run from powershell?

From Dev

How to run a .class file that is part of a package from cmd?

From Dev

how to run cmd from batch file and go to folder within parent folder

From Dev

Run cmd command work but run from batch file doesn't

From Dev

How to run a batch file as administrator from a java program

From Dev

Windows startup - how to run a program as administrator from a batch file

From Dev

How to launch MSTest and run a command from batch file?

From Dev

Removing character from 'type' in cmd batch file

From Dev

Windows XP, Can run .jar from cmd prompt, but batch file errors on "Cannot access jar file"

From Dev

Echo output from commands in a batch file to the cmd

From Dev

How to make a batch file that will run multiple queries in cmd and log them

From Dev

how to run batch file from java code?

From Dev

Run batch file with my own command in cmd?

From Dev

How to run python file in cmd?

From Dev

How to run a multi-arguments batch file from a vbscript in CMD?

From Dev

How to open cmd and run a batch file in it in one command

From Dev

How do I shift the execution of a batch file from one CMD to another CMD?

From Dev

How to run crontabs with sudo R CMD BATCH?

From Dev

How to run a lua file in cmd from Sublime Text 3?

From Dev

How can I run a batch file which gets drive space and keeps CMD open?

From Dev

Starting a batch file from another batch file only opens CMD

From Dev

How to run a batch file from Jenkins

From Dev

How to run this "batch" file?

From Dev

How to remove new line from text file in for loop (CMD/Batch)

From Dev

Run Batch File from R

From Dev

How to run batch file using Runas command from a batch file

From Dev

How to close cmd in batch file

From Dev

Create A Batch File from a Notepad to CMD

Related Related

  1. 1

    How to run a PowerShell script from a batch file

  2. 2

    In a CMD batch file, can I determine if it was run from powershell?

  3. 3

    How to run a .class file that is part of a package from cmd?

  4. 4

    how to run cmd from batch file and go to folder within parent folder

  5. 5

    Run cmd command work but run from batch file doesn't

  6. 6

    How to run a batch file as administrator from a java program

  7. 7

    Windows startup - how to run a program as administrator from a batch file

  8. 8

    How to launch MSTest and run a command from batch file?

  9. 9

    Removing character from 'type' in cmd batch file

  10. 10

    Windows XP, Can run .jar from cmd prompt, but batch file errors on "Cannot access jar file"

  11. 11

    Echo output from commands in a batch file to the cmd

  12. 12

    How to make a batch file that will run multiple queries in cmd and log them

  13. 13

    how to run batch file from java code?

  14. 14

    Run batch file with my own command in cmd?

  15. 15

    How to run python file in cmd?

  16. 16

    How to run a multi-arguments batch file from a vbscript in CMD?

  17. 17

    How to open cmd and run a batch file in it in one command

  18. 18

    How do I shift the execution of a batch file from one CMD to another CMD?

  19. 19

    How to run crontabs with sudo R CMD BATCH?

  20. 20

    How to run a lua file in cmd from Sublime Text 3?

  21. 21

    How can I run a batch file which gets drive space and keeps CMD open?

  22. 22

    Starting a batch file from another batch file only opens CMD

  23. 23

    How to run a batch file from Jenkins

  24. 24

    How to run this "batch" file?

  25. 25

    How to remove new line from text file in for loop (CMD/Batch)

  26. 26

    Run Batch File from R

  27. 27

    How to run batch file using Runas command from a batch file

  28. 28

    How to close cmd in batch file

  29. 29

    Create A Batch File from a Notepad to CMD

HotTag

Archive