Created
February 22, 2021 13:01
-
-
Save libnumafly/af511503970f7c836dec5b48ef0e71b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
echo. | |
if "%2"=="" ( echo Too few arguments. && exit /b ) | |
set WorkDir=TMP | |
set ESDFile=%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 WorkDir= %WorkDir% | |
echo ESDFile= %ESDFile%.esd | |
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 | |
cd /d %~dp0 | |
echo. | |
echo ***Making work directory...*** | |
if exist %WorkDir% goto DeleteWorkDir | |
goto NoDeleteWorkDir | |
:DeleteWorkDir | |
echo Removing old work directory. | |
rmdir /S /Q %WorkDir% | |
:NoDeleteWorkDir | |
mkdir %WorkDir% | |
echo. | |
echo ***Show %ESDFile%.esd information...*** | |
Dism /Get-WIMInfo /WimFile:%ESDFile%.esd | |
echo. | |
echo ***Exporting %ESDFile%.esd to %ESDFile%.wim...*** | |
Dism /Export-Image /SourceImageFile:%ESDFile%.esd /SourceName:"Windows 10 Pro" /DestinationImageFile:%ESDFile%.wim /Compress:none /CheckIntegrity | |
echo Exported successfly. | |
echo ***Show %ESDFile%.wim information...*** | |
Dism /Get-WIMInfo /WimFile:%ESDFile%.wim | |
echo. | |
echo ***Now, let's try to mount %ESDFile%.wim to working directory to apply update images.*** | |
Dism /Mount-WIM /WimFile:%ESDFile%.wim /Name:"Windows 10 Pro" /MountDir:%WorkDir% | |
if errorlevel 1 goto DISM_NG | |
goto DISM_OK | |
:DISM_NG | |
echo Can't mount WIM correctly. Script stopped. Hit some key to exit. | |
pause | |
exit /b | |
:DISM_OK | |
echo ***Mounted %ESDFile%.wim to %WorkDir% is successful.*** | |
echo. | |
if not "%PackagePath1%"=="" call :RunApplyPackage %WorkDir% %PackagePath1% | |
if not "%PackagePath2%"=="" call :RunApplyPackage %WorkDir% %PackagePath2% | |
if not "%PackagePath3%"=="" call :RunApplyPackage %WorkDir% %PackagePath3% | |
if not "%PackagePath4%"=="" call :RunApplyPackage %WorkDir% %PackagePath4% | |
if not "%PackagePath5%"=="" call :RunApplyPackage %WorkDir% %PackagePath5% | |
if not "%PackagePath6%"=="" call :RunApplyPackage %WorkDir% %PackagePath6% | |
if not "%PackagePath7%"=="" call :RunApplyPackage %WorkDir% %PackagePath7% | |
if not "%PackagePath8%"=="" call :RunApplyPackage %WorkDir% %PackagePath8% | |
:ENDPACKAGEAPPLY | |
echo ***Cleaning up...*** | |
Dism /Image:%WorkDir% /Cleanup-Image /StartComponentCleanup /ResetBase | |
echo OKAY. | |
echo. | |
echo *** Commit and unmount image from working directory... *** | |
Dism /Unmount-Image /MountDir:%WorkDir% /Commit /CheckIntegrity | |
echo OKAY. | |
echo. | |
echo ***Cleaning up...*** | |
Dism /Cleanup-Mountpoints | |
Dism /Cleanup-WIM | |
echo OKAY. | |
echo. | |
echo ***At the end, generating new %ESDFile%.esd image...*** | |
move %ESDFile%.esd %ESDFile%.old.esd | |
Dism /Export-Image /SourceImageFile:%ESDFile%.wim /SourceName:"Windows 10 Pro" /DestinationImageFile:%ESDFile%.esd /Compress:recovery /CheckIntegrity | |
echo OKAY. | |
echo. | |
echo *** Removing old working directory... *** | |
rmdir /S /Q %WorkDir% | |
del /Q %ESDFile%.wim | |
:ExitBatch | |
exit /b | |
:ExitBatchWithError | |
echo *** Woah, EMERGENCY STOPPED because it's seems something went wrong. *** | |
echo *** Now, executing unmount and clean-up... *** | |
Dism /Unmount-Image /MountDir:%WorkDir% /Discard | |
Dism /Cleanup-Mountpoints | |
Dism /Cleanup-WIM | |
REM ### CAUTION, USE THOSE BELOW LABELS ONLY WITH CALL SUB-ROUTINE, NOT GOTO !!! ### | |
:RunApplyPackage | |
Dism /Image:%1 /Add-Package /PackagePath:%2 | |
echo OKAY. | |
echo. | |
exit /b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment