Skip to content

Instantly share code, notes, and snippets.

@libnumafly
Created February 22, 2021 13:02
Show Gist options
  • Save libnumafly/99aeaad2bfb2571f5927b2b4dd0f2c1e to your computer and use it in GitHub Desktop.
Save libnumafly/99aeaad2bfb2571f5927b2b4dd0f2c1e to your computer and use it in GitHub Desktop.
@echo off
echo.
if "%2"=="" ( echo Too few arguments. && exit /b )
set ScratchDir=SCRATCH
set TargetImage=%1
set PackagePath1=%2
set PackagePath2=%3
set PackagePath3=%4
set PackagePath4=%5
set PackagePath5=%6
set PackagePath6=%7
set PackagePath7=%8
set PackagePath8=%9
echo *** Script variable is below. ***
echo ScratchDir= %ScratchDir%
echo TargetImage= %TargetImage%
echo PackagePath1= %PackagePath1%
echo PackagePath2= %PackagePath2%
echo PackagePath3= %PackagePath3%
echo PackagePath4= %PackagePath4%
echo PackagePath5= %PackagePath5%
echo PackagePath6= %PackagePath6%
echo PackagePath7= %PackagePath7%
echo PackagePath8= %PackagePath8%
echo *** Is that right, hit some key. if you not mind, don't hit key and close this window. ****
pause
echo.
echo Script file location is: %~dp0
echo Target system drive is: %TargetImage%
cd /d %~dp0
echo.
echo ***Making working directory...***
if exist %ScratchDir% goto DeleteScratchDir
goto NoDeleteScratchDir
:DeleteScratchDir
echo Removing old working directory.
rmdir /S /Q %ScratchDir%
:NoDeleteScratchDir
mkdir %ScratchDir%
echo.
if not "%PackagePath1%"=="" call :RunApplyPackage %TargetImage% %PackagePath1% %ScratchDir%
if not "%PackagePath2%"=="" call :RunApplyPackage %TargetImage% %PackagePath2% %ScratchDir%
if not "%PackagePath3%"=="" call :RunApplyPackage %TargetImage% %PackagePath3% %ScratchDir%
if not "%PackagePath4%"=="" call :RunApplyPackage %TargetImage% %PackagePath4% %ScratchDir%
if not "%PackagePath5%"=="" call :RunApplyPackage %TargetImage% %PackagePath5% %ScratchDir%
if not "%PackagePath6%"=="" call :RunApplyPackage %TargetImage% %PackagePath6% %ScratchDir%
if not "%PackagePath7%"=="" call :RunApplyPackage %TargetImage% %PackagePath7% %ScratchDir%
if not "%PackagePath8%"=="" call :RunApplyPackage %TargetImage% %PackagePath8% %ScratchDir%
:ENDPACKAGEAPPLY
echo ***Cleaning up...***
Dism /Image:%TargetImage% /Cleanup-Image /StartComponentCleanup /ResetBase /ScratchDir=%ScratchDir%
echo OKAY.
echo.
echo *** Removing old working directory... ***
rmdir /S /Q %ScratchDir%
:ExitBatch
exit /b
REM ### CAUTION, USE THOSE BELOW LABELS ONLY WITH CALL SUB-ROUTINE, NOT GOTO !!! ###
:RunApplyPackage
Dism /Image=%1 /Add-Package /PackagePath:%2 /ScratchDir=%3
echo OKAY.
echo.
exit /b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment