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rMINyiwjCnxzIrXFuEQq9aY1930q5XgYfoV8OZirdIWKYtvPWzBgEkmi5w930kqjRyA81XwhH74guWww7A1lImbygBDl5wyE8GRVg2Emy7pU2sybyvtjMLSBgmTK8h6UqEXaupvuVCYjC8BzkUGWfTG9eh50TPpFZMO4vB2l2tbfwA2oTBwvjuwaDwdUIFXYjmdti3A+EGuhvDAeGzGxZhOmQir84CYXEKMj4yaqFvaKecMCtOOwWWpAEIzRWxXJIXN6EPqiZGEauZUAXjicVI/jpkKGhWUnaLZhNFTYD6Nl/eBMA2TPj6w4AiOnr21bDjgE="

rem script:     abbodi1406
rem esddecrypt: qad
rem wimlib:     synchronicity
rem cryptokey:  Chris123NT, MrMagic, mohitbajaj143, Superwzt

set "params=%*"
cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" ) && fsutil dirty query %systemdrive% 1>nul 2>nul || (  echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /B )
title ESD ^> ISO
if not exist "%~dp0bin\wimlib-imagex.exe" goto :eof
if not exist "%~dp0bin\dism.exe" goto :eof
set "wimlib=%~dp0bin\wimlib-imagex.exe"
%windir%\system32\reg.exe query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE | find /i "amd64" 1>nul && set "wimlib=%~dp0bin\bin64\wimlib-imagex.exe"
cd /d "%~dp0"
setlocal EnableDelayedExpansion
color 1f
SET Backup=OFF
SET ENCRYPTEDESD=
SET ERRORTEMP=
SET ENCRYPTED=0
SET MULTI=0
SET PREPARED=0
SET VOL=0
SET "ramdiskoptions={7619dcc8-fafe-11d9-b411-000476eba25f}"

if not [%1]==[] (set "ENCRYPTEDESD=%~1"&set "ENCRYPTEDESDN=%~nx1"&goto :check)
set _esd=0
if exist "*.esd" (for /f "delims=" %%i in ('dir /b "*.esd"') do (call set /a _esd+=1))
if !_esd! equ 2 goto :dCheck
if !_esd! equ 0 goto :prompt1
if !_esd! gtr 1 goto :prompt2
for /f "delims=" %%i in ('dir /b "*.esd"') do (set "ENCRYPTEDESD=%%i"&set "ENCRYPTEDESDN=%%i"&goto :check)

:prompt1
cls
echo.
echo ============================================================
echo   键入或粘贴 ESD 文件的完整路径
echo   ^(即使文件路径中存在空格，也不能包括引号 ""^)
echo ============================================================
echo.
set /p ENCRYPTEDESD=
if [%ENCRYPTEDESD%]==[] goto :QUIT
call :setvar "%ENCRYPTEDESD%"
goto :check

:setvar
SET ENCRYPTEDESDN=%~nx1
goto :eof

:prompt2
cls
echo.
echo ============================================================
echo  在当前的目录下找到 ESD 文件数量不止一个
echo  键入需要处理的文件名称来进行处理
echo  你可以使用 "Tab" 键来进行选择
echo ============================================================
echo.
set /p ENCRYPTEDESD=
if [%ENCRYPTEDESD%]==[] goto :QUIT
SET ENCRYPTEDESDN=%ENCRYPTEDESD%
goto :check

:check
SET ENCRYPTED=0
if /i %ENCRYPTEDESDN%==install.esd (ren %ENCRYPTEDESD% %ENCRYPTEDESDN%.orig&set ENCRYPTEDESD=%ENCRYPTEDESD%.orig)
bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 5 >nul 2>&1
IF %ERRORLEVEL% EQU 0 SET MULTI=1&GOTO :MAINMENU
bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 >nul 2>&1
IF %ERRORLEVEL% EQU 74 SET ENCRYPTED=1&GOTO :MAINMENU
IF %ERRORLEVEL% EQU 18 (
cls
echo.
echo =================================================================
echo  错误提示: ESD 文件没有原始的结构 ^(4 到 5 个映像文件^)。
echo =================================================================
echo.
echo  请按任意键退出脚本。
pause >nul
goto :eof
)
IF %ERRORLEVEL% NEQ 0 (
cls
echo.
echo ============================================================
echo  错误提示: 指定的 ESD 文件已被损坏，丢失或者没有找到。
echo ============================================================
echo.
echo 请按任意键退出脚本。
pause >nul
goto :eof
)

:MAINMENU
cls
echo ============================================================
echo.       1 - 创建一个包含标准 install.wim 的 ISO 镜像
echo.       2 - 创建一个包含压缩 install.esd 的 ISO 镜像
echo.       3 - 创建一个标准的 install.wim 文件
echo.       4 - 创建一个压缩的 install.esd 文件
IF %ENCRYPTED%==1 (
echo.       5 - 仅对 ESD 文件进行解密
echo ____________________________________________________________
echo  加密的 ESD 文件备份状态： %Backup%。请按数字键 9 以切换。
) else (
echo.       5 - 查阅当前的 ESD 文件信息
)
echo ============================================================
echo.
choice /c 1234590 /n /m "在菜单中选择一个项目，或者按数字键 0 退出脚本:"
if errorlevel 7 GOTO :QUIT
if errorlevel 6 (if /i %Backup% equ OFF (set Backup=ON) else (set Backup=OFF))&goto :MAINMENU
if errorlevel 5 (if %ENCRYPTED%==1 (GOTO :DDECRYPT) else (GOTO :INFO))
if errorlevel 4 (set WIMFILE=install.esd&goto :Single)
if errorlevel 3 (set WIMFILE=install.wim&goto :Single)
if errorlevel 2 (set WIMFILE=install.esd&goto :ISO)
if errorlevel 1 (set WIMFILE=install.wim&goto :ISO)
GOTO :MAINMENU

:ISO
cls
echo.
IF %ENCRYPTED%==1 CALL :DECRYPT
IF %PREPARED%==0 CALL :PREPARE
echo ============================================================
echo  正在为安装镜像进行布局...
echo ============================================================
IF EXIST ISOFOLDER\ rmdir /s /q ISOFOLDER\
mkdir ISOFOLDER
echo.
"%wimlib%" apply "%ENCRYPTEDESD%" 1 ISOFOLDER\ >nul 2>&1
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo  在应用映像的时候报告了一个错误。&PAUSE&GOTO :QUIT)
del ISOFOLDER\MediaMeta.xml >nul 2>&1
echo.
echo ============================================================
echo  正在创建 %WIMFILE%...
echo ============================================================
echo.
if /i %WIMFILE%==install.esd (
"%wimlib%" export "%ENCRYPTEDESD%" 4 ISOFOLDER\sources\%WIMFILE%
) else (
"%wimlib%" export "%ENCRYPTEDESD%" 4 ISOFOLDER\sources\%WIMFILE% --compress=maximum
)
IF %MULTI%==1 echo.&"%wimlib%" export "%ENCRYPTEDESD%" 5 ISOFOLDER\sources\%WIMFILE%
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo  在导出映像的时候报告了一个错误。&PAUSE&GOTO :QUIT)
echo.
echo ============================================================
echo 正在提取 winre.wim...
echo ============================================================
echo.
"%wimlib%" extract ISOFOLDER\sources\%WIMFILE% 1 Windows\System32\Recovery\winre.wim --dest-dir=.\ISOFOLDER\sources --no-acls
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo Errors were reported during extracting.&PAUSE&GOTO :QUIT)
copy /y .\bin\reagent.xml .\ISOFOLDER\sources >nul 2>&1
bin\bcdedit.exe /store ISOFOLDER\boot\BCD /set {default} device ramdisk=[boot]\sources\winre.wim,%ramdiskoptions% >nul 2>&1
bin\bcdedit.exe /store ISOFOLDER\boot\BCD /set {default} osdevice ramdisk=[boot]\sources\winre.wim,%ramdiskoptions% >nul 2>&1
bin\bcdedit.exe /store ISOFOLDER\efi\Microsoft\boot\BCD /set {default} device ramdisk=[boot]\sources\winre.wim,%ramdiskoptions% >nul 2>&1
bin\bcdedit.exe /store ISOFOLDER\efi\Microsoft\boot\BCD /set {default} osdevice ramdisk=[boot]\sources\winre.wim,%ramdiskoptions% >nul 2>&1
echo.
echo ============================================================
echo  正在写入 ISO 镜像文件...
echo ============================================================
IF %MULTI%==1 (set sourcetime=2) else (set sourcetime=1)
for /f "tokens=5,6,7,8,9,10 delims=: " %%G in ('bin\wimlib-imagex.exe info ISOFOLDER\sources\%WIMFILE% %sourcetime% ^| find /i "Last Modification Time"') do (set mmm=%%G&set "isotime=%%H/%%L,%%I:%%J:%%K")
call :setdate %mmm%
bin\cdimage.exe -bootdata:2#p0,e,b"ISOFOLDER\boot\etfsboot.com"#pEF,e,b"ISOFOLDER\efi\Microsoft\boot\efisys.bin" -o -m -u2 -udfver102 -t%isotime% -g -l%DVDLABEL% ISOFOLDER %DVDISO%
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (
echo.
echo  在写入ISO镜像文件的过程中报告了一个错误。
echo.
echo  请按任意键退出脚本。
pause >nul
IF EXIST "%ENCRYPTEDESD%.bak" (
del /f /q "%ENCRYPTEDESD%" >nul 2>&1
ren "%ENCRYPTEDESD%.bak" %ENCRYPTEDESDN%
)
exit
)
rmdir /s /q ISOFOLDER\
echo.
echo  请按任意键退出脚本。
pause >nul
GOTO :QUIT

:Single
cls
if %WIMFILE%==install.wim IF EXIST "%CD%\install.wim" (
echo.
echo ============================================================
echo  在当前的目录中已经存在一个 install.wim 文件。
echo ============================================================
echo.
echo  请按任意键退出脚本。
pause >nul
GOTO :QUIT
)
echo.
IF %ENCRYPTED%==1 CALL :DECRYPT
bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 5 1>nul 2>nul && SET MULTI=1
echo ============================================================
echo  正在创建 %WIMFILE% 文件...
echo ============================================================
echo.
if /i %WIMFILE%==install.esd (
"%wimlib%" export "%ENCRYPTEDESD%" 4 %WIMFILE%
) else (
"%wimlib%" export "%ENCRYPTEDESD%" 4 %WIMFILE% --compress=maximum
)
IF %MULTI%==1 echo.&"%wimlib%" export "%ENCRYPTEDESD%" 5 %WIMFILE%
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo  在导出映像的时候报告了一个错误。&PAUSE&GOTO :QUIT)
echo.
echo  已完成要求的操作。
echo.
echo  请按任意键退出脚本。
pause >nul
GOTO :QUIT

:INFO
IF %PREPARED%==0 CALL :PREPARE
cls
echo ============================================================
echo                     ESD 文件详细信息
echo ============================================================
echo.
IF %MULTI%==1 (
echo      索引 1: %_os%
echo      索引 2: %_os2%
) else (
echo      操作系统: %_os%
)
echo      架构: %arch%
echo      语言: %langid%
echo      系统版本: %_ver%.%svcbuild%
if defined branch echo      分支: %branch%
echo.
echo 请按任意键继续...
pause >nul
GOTO :MAINMENU

:PREPARE
SET PREPARED=1
for /f "tokens=2 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| findstr /b "Build"') do set build=%%i
if %build% LEQ 9600 GOTO :E_W81
for /f "tokens=2* delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Display Name"') do set "_os=%%j"
if ["%_os%"]==[""] (for /f "tokens=1* delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| findstr /b "Name"') do set "_os=%%j")
if %MULTI%==1 (for /f "tokens=2* delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 5 ^| find /i "Display Name"') do set "_os2=%%j")
if %MULTI%==1 if ["%_os2%"]==[""] (for /f "tokens=1* delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 5 ^| findstr /b "Name"') do set "_os2=%%j")
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Major"') do set _ver1=%%i
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Minor"') do set _ver2=%%i
set _ver=%_ver1%.%_ver2%.%build%
bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 5 1>nul 2>nul && SET MULTI=1
for /f "tokens=2 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Architecture"') do set arch=%%i
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Edition"') do set editionid=%%i
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Default"') do set langid=%%i
for /f "tokens=4 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Service Pack Build"') do set svcbuild=%%i
"%wimlib%" extract "%ENCRYPTEDESD%" 1 sources\ei.cfg --dest-dir=.\bin\temp --no-acls >nul 2>&1
type .\bin\temp\ei.cfg 2>nul | find /i "Volume" 1>nul && set VOL=1
"%wimlib%" extract "%ENCRYPTEDESD%" 3 sources\SetupPlatform.dll --dest-dir=.\bin\temp --no-acls >nul 2>&1
bin\7z.exe l .\bin\temp\SetupPlatform.dll >.\bin\temp\version.txt 2>&1
for /f "tokens=4,5 delims=. " %%i in ('"findstr /B "FileVersion" .\bin\temp\version.txt" 2^>nul') do set version=%%i.%%j
for /f "tokens=7 delims=.) " %%i in ('"findstr /B "FileVersion" .\bin\temp\version.txt" 2^>nul') do set datetime=%%i
for /f "tokens=6 delims=.( " %%i in ('"findstr /B "FileVersion" .\bin\temp\version.txt" 2^>nul') do set branch=%%i
if /i %arch%==x86 (set _ss=x86) else (set _ss=amd64)
"%wimlib%" extract "%ENCRYPTEDESD%" 4 Windows\WinSxS\Manifests\%_ss%_microsoft-windows-coreos-revision* --dest-dir=.\bin\temp --no-acls >nul 2>&1
for /f "tokens=6,7 delims=_." %%i in ('dir /b .\bin\temp\*.manifest') do set revision=%%i.%%j
if %version% neq %revision% (
set version=%revision%
for /f "tokens=5,6,7,8,9,10 delims=: " %%G in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Last Modification Time"') do (set mmm=%%G&set yyy=%%L&set ddd=%%H-%%I%%J)
call :setmmm !mmm!
)
if %revision%==10240.16487 (set version=10240.16393&set datetime=150909-1450&set branch=th1_refresh)
if %revision%==10586.104 (set version=10586.0&set datetime=160212-2000&set branch=th2_refresh)
if defined branch for %%b in (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do set branch=!branch:%%b=%%b!
if defined branch set _label=%version%.%datetime%.%branch%_CLIENT
rd /s /q .\bin\temp

set lang=%langid:~0,2%
if /i %langid%==en-gb set lang=en-gb
if /i %langid%==es-mx set lang=es-mx
if /i %langid%==fr-ca set lang=fr-ca
if /i %langid%==pt-pt set lang=pp
if /i %langid%==sr-latn-rs set lang=sr-latn
if /i %langid%==zh-cn set lang=cn
if /i %langid%==zh-tw set lang=tw
if /i %langid%==zh-hk set lang=hk
for %%b in (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do set langid=!langid:%%b=%%b!

if /i %arch%==x86 set archl=X86
if /i %arch%==x86_64 set arch=x64&set archl=X64

IF %MULTI%==1 (
if /i %editionid%==Professional set DVDLABEL=J_CCSA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PRO-CORE_OEMRET_%archl%FRE_%langid%.ISO
if /i %editionid%==ProfessionalN set DVDLABEL=J_CCSNA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PRON-COREN_OEMRET_%archl%FRE_%langid%.ISO
if defined branch exit /b
)
if /i %editionid%==Core set DVDLABEL=J_CCRA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%CORE_OEMRET_%archl%FRE_%langid%.ISO
if /i %editionid%==CoreN set DVDLABEL=J_CCRNA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%COREN_OEMRET_%archl%FRE_%langid%.ISO
if /i %editionid%==CoreSingleLanguage set DVDLABEL=J_CSLA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%SINGLELANGUAGE_OEM_%archl%FRE_%langid%.ISO
if /i %editionid%==CoreCountrySpecific set DVDLABEL=J_CCHA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%CHINA_OEM_%archl%FRE_%langid%.ISO
if /i %editionid%==Professional (IF %VOL%==1 (set DVDLABEL=J_CPRA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%PROFESSIONALVL_VOL_%archl%FRE_%langid%.ISO) else (set DVDLABEL=J_CPRA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PRO_OEMRET_%archl%FRE_%langid%.ISO))
if /i %editionid%==ProfessionalN (IF %VOL%==1 (set DVDLABEL=J_CPRNA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%PROFESSIONALNVL_VOL_%archl%FRE_%langid%.ISO) else (set DVDLABEL=J_CPRNA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PRON_OEMRET_%archl%FRE_%langid%.ISO))
if /i %editionid%==Education (IF %VOL%==1 (set DVDLABEL=J_CEDA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%EDUCATION_VOL_%archl%FRE_%langid%.ISO) else (set DVDLABEL=J_CEDA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%EDUCATION_RET_%archl%FRE_%langid%.ISO))
if /i %editionid%==EducationN (IF %VOL%==1 (set DVDLABEL=J_CEDNA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%EDUCATIONN_VOL_%archl%FRE_%langid%.ISO) else (set DVDLABEL=J_CEDNA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%EDUCATIONN_RET_%archl%FRE_%langid%.ISO))
if /i %editionid%==Enterprise set DVDLABEL=J_CENA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISE_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==EnterpriseN set DVDLABEL=J_CENNA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISEN_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==EnterpriseS set DVDLABEL=J_CES_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISES_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==EnterpriseSN set DVDLABEL=J_CESN_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISESN_VOL_%archl%FRE_%langid%.ISO
if defined branch exit /b

IF %MULTI%==1 (
if /i %editionid%==Professional set DVDLABEL=J_CCSA_%archl%FRE_%langid%_DV5&set DVDISO=%lang%_windows_10_multiple_editions_%build%.%svcbuild%_%arch%_dvd.iso
if /i %editionid%==ProfessionalN set DVDLABEL=J_CCSNA_%archl%FRE_%langid%_DV5&set DVDISO=%lang%_windows_10_n_multiple_editions_%build%.%svcbuild%_%arch%_dvd.iso
exit /b
)
if /i %editionid%==Core set DVDLABEL=J_CCRA_%archl%FRE_%langid%_DV5&set DVDISO=%lang%_windows_10_home_%build%.%svcbuild%_%arch%_dvd.iso
if /i %editionid%==CoreN set DVDLABEL=J_CCRNA_%archl%FRE_%langid%_DV5&set DVDISO=%lang%_windows_10_home_n_%build%.%svcbuild%_%arch%_dvd.iso
if /i %editionid%==CoreSingleLanguage set DVDLABEL=J_CSLA_%archl%FRE_%langid%_DV5&set DVDISO=%lang%_windows_10_home_singlelanguage_%build%.%svcbuild%_%arch%_dvd.iso
if /i %editionid%==CoreCountrySpecific set DVDLABEL=J_CCHA_%archl%FRE_%langid%_DV5&set DVDISO=%lang%_windows_10_home_china_%build%.%svcbuild%_%arch%_dvd.iso
if /i %editionid%==Professional (IF %VOL%==1 (set DVDLABEL=J_CPRA_%archl%FREV_%langid%_DV5&set DVDISO=%lang%_windows_10_professional_vl_%build%.%svcbuild%_%arch%_dvd.iso) else (set DVDLABEL=J_CPRA_%archl%FRE_%langid%_DV5&set DVDISO=%lang%_windows_10_pro_%build%.%svcbuild%_%arch%_dvd.iso))
if /i %editionid%==ProfessionalN (IF %VOL%==1 (set DVDLABEL=J_CPRNA_%archl%FREV_%langid%_DV5&set DVDISO=%lang%_windows_10_professional_n_vl_%build%.%svcbuild%_%arch%_dvd.iso) else (set DVDLABEL=J_CPRNA_%archl%FRE_%langid%_DV5&set DVDISO=%lang%_windows_10_pro_n_%build%.%svcbuild%_%arch%_dvd.iso))
if /i %editionid%==Education (IF %VOL%==1 (set DVDLABEL=J_CEDA_%archl%FREV_%langid%_DV5&set DVDISO=%lang%_windows_10_education_vl_%build%.%svcbuild%_%arch%_dvd.iso) else (set DVDLABEL=J_CEDA_%archl%FRE_%langid%_DV5&set DVDISO=%lang%_windows_10_education_%build%.%svcbuild%_%arch%_dvd.iso))
if /i %editionid%==EducationN (IF %VOL%==1 (set DVDLABEL=J_CEDNA_%archl%FREV_%langid%_DV5&set DVDISO=%lang%_windows_10_education_n_vl_%build%.%svcbuild%_%arch%_dvd.iso) else (set DVDLABEL=J_CEDNA_%archl%FRE_%langid%_DV5&set DVDISO=%lang%_windows_10_education_n_%build%.%svcbuild%_%arch%_dvd.iso))
if /i %editionid%==Enterprise set DVDLABEL=J_CENA_%archl%FREV_%langid%_DV5&set DVDISO=%lang%_windows_10_enterprise_%build%.%svcbuild%_%arch%_dvd.iso
if /i %editionid%==EnterpriseN set DVDLABEL=J_CENNA_%archl%FREV_%langid%_DV5&set DVDISO=%lang%_windows_10_enterprise_n_%build%.%svcbuild%_%arch%_dvd.iso
if /i %editionid%==EnterpriseS set DVDLABEL=J_CES_%archl%FREV_%langid%_DV5&set DVDISO=%lang%_windows_10_enterprise_2016_ltsb_%build%.%svcbuild%_%arch%_dvd.iso
if /i %editionid%==EnterpriseSN set DVDLABEL=J_CESNN_%archl%FREV_%langid%_DV5&set DVDISO=%lang%_windows_10_enterprise_2016_ltsb_n_%build%.%svcbuild%_%arch%_dvd.iso
exit /b

:setdate
if /i %1==Jan set "isotime=01/%isotime%"
if /i %1==Feb set "isotime=02/%isotime%"
if /i %1==Mar set "isotime=03/%isotime%"
if /i %1==Apr set "isotime=04/%isotime%"
if /i %1==May set "isotime=05/%isotime%"
if /i %1==Jun set "isotime=06/%isotime%"
if /i %1==Jul set "isotime=07/%isotime%"
if /i %1==Aug set "isotime=08/%isotime%"
if /i %1==Sep set "isotime=09/%isotime%"
if /i %1==Oct set "isotime=10/%isotime%"
if /i %1==Nov set "isotime=11/%isotime%"
if /i %1==Dec set "isotime=12/%isotime%"
exit /b

:setmmm
if /i %1==Jan set "datetime=%yyy:~2%01%ddd%"
if /i %1==Feb set "datetime=%yyy:~2%02%ddd%"
if /i %1==Mar set "datetime=%yyy:~2%03%ddd%"
if /i %1==Apr set "datetime=%yyy:~2%04%ddd%"
if /i %1==May set "datetime=%yyy:~2%05%ddd%"
if /i %1==Jun set "datetime=%yyy:~2%06%ddd%"
if /i %1==Jul set "datetime=%yyy:~2%07%ddd%"
if /i %1==Aug set "datetime=%yyy:~2%08%ddd%"
if /i %1==Sep set "datetime=%yyy:~2%09%ddd%"
if /i %1==Oct set "datetime=%yyy:~2%10%ddd%"
if /i %1==Nov set "datetime=%yyy:~2%11%ddd%"
if /i %1==Dec set "datetime=%yyy:~2%12%ddd%"
exit /b

:DDECRYPT
cls
CALL :DECRYPT
ren "%ENCRYPTEDESD%" 已解密-%ENCRYPTEDESDN%
echo.
echo  已完成要求的操作。
echo.
echo  请按任意键退出脚本。
pause >nul
GOTO :QUIT

:DECRYPT
if /i %Backup%==ON (
echo ============================================================
echo  正在备份加密的 esd 文件...
echo ============================================================
copy /y "%ENCRYPTEDESD%" "%ENCRYPTEDESD%.bak" >nul
)
echo.
echo ============================================================
echo  正在备份加密的 esd 文件...
echo ============================================================
echo.
bin\esddecrypt.exe "%ENCRYPTEDESD%" %cryptokey1% 2>nul&&exit /b
bin\esddecrypt.exe "%ENCRYPTEDESD%" %cryptokey2% 2>nul&&exit /b
bin\esddecrypt.exe "%ENCRYPTEDESD%" %cryptokey3% 2>nul&&exit /b
bin\esddecrypt.exe "%ENCRYPTEDESD%" %cryptokey4% 2>nul&&exit /b
bin\esddecrypt.exe "%ENCRYPTEDESD%" %cryptokey5% 2>nul&&exit /b
bin\esddecrypt.exe "%ENCRYPTEDESD%" %cryptokey6% 2>nul&&exit /b
bin\esddecrypt.exe "%ENCRYPTEDESD%" &&exit /b
echo.
echo  在解密 ESD 文件的过程中报告了一个错误。
echo.
echo  请按任意键退出脚本。
pause >nul
GOTO :QUIT

:E_W81
cls
echo.
echo ============================================================
echo  错误提示: 本脚本仅支持处理 Windows 10 的 ESD文件。
echo  你可以使用旧版脚本处理 Windows 8.1 的 ESD文件。
echo ============================================================
echo.
echo  请按任意键退出脚本。
pause >nul
goto :QUIT

:dCheck
SET combine=0
SET count=0
SET ESDmulti1=0
SET ESDmulti2=0
SET ESDenc1=0
SET ESDenc2=0
set ESDvol1=0
set ESDvol2=0
set ESDarch1=0
set ESDarch2=0
set ESDver1=0
set ESDver2=0
set ESDlang1=0
set ESDlang2=0
for /f "delims=" %%i in ('dir /b "*.esd"') do call :dCount %%i
CALL :dInfo 1
CALL :dInfo 2
if /i %ESDarch1% equ %ESDarch2% goto :prompt2
if /i %ESDver1% neq %ESDver2% goto :prompt2
if /i %ESDlang1% neq %ESDlang2% goto :prompt2
bin\wimlib-imagex.exe info "%ESDfile1%" 4 >nul 2>&1
IF %ERRORLEVEL% EQU 74 SET ENCRYPTED=1
bin\wimlib-imagex.exe info "%ESDfile2%" 4 >nul 2>&1
IF %ERRORLEVEL% EQU 74 SET ENCRYPTED=1

:DUALMENU
cls
echo.
echo  检测到 2 个 ESD 文件是同一版本但分属不同的硬件架构。
echo ____________________________________________________________________________
echo.
echo  你想创建一个多架构版本的 ISO 镜像吗？
echo.
echo  1- 创建同时包含两个压缩 install.esd 的 ISO 镜像                 ^(等效于 MediaCreationTool^)
echo  2- 创建同时包含两个标准 install.wim 的 ISO 镜像           ^(类似于选项1，文件体积较大^)
echo  3- 创建一个包含用于共享的 install.wim 的 ISO 镜像         ^(整体的文件尺寸较小^)
echo.
echo  4- 不，我只想继续快速的处理其中的一个文件
IF %ENCRYPTED%==1 (
echo ____________________________________________________________________________
echo  加密的 ESD 文件备份状态： %Backup%。请按数字键 9 以进行切换。
)
echo.
choice /c 12349 /N /M "键入你的选项代码> "
if errorlevel 5 (if /i %Backup% equ OFF (set Backup=ON) else (set Backup=OFF))&goto :DUALMENU
if errorlevel 4 goto :prompt2
if errorlevel 3 (set WIMFILE=install.wim&set combine=1&goto :Dual)
if errorlevel 2 (set WIMFILE=install.wim&goto :Dual)
if errorlevel 1 (set WIMFILE=install.esd&goto :Dual)
GOTO :DUALMENU

:dCount
set /a count+=1
set "ESDfile%count%=%1
goto :eof

:dInfo
for /f "skip=1 tokens=2 delims=: " %%i in ('bin\dism.exe /english /get-wiminfo /wimfile:"!ESDfile%1!" /index:4 ^| find /i "Version"') do set ESDver%1=%%i
for /f "tokens=2 delims=: " %%i in ('bin\dism.exe /english /get-wiminfo /wimfile:"!ESDfile%1!" /index:4 ^| find /i "Edition"') do set ESDedition%1=%%i
for /f "tokens=2 delims=: " %%i in ('bin\dism.exe /english /get-wiminfo /wimfile:"!ESDfile%1!" /index:4 ^| find /i "Architecture"') do set ESDarch%1=%%i
for /f "tokens=1" %%i in ('bin\dism.exe /english /get-wiminfo /wimfile:"!ESDfile%1!" /index:4 ^| find /i "Default"') do set ESDlang%1=%%i
for /f "tokens=2 delims=: " %%i in ('bin\dism.exe /english /Get-WimInfo /WimFile:"!ESDfile%1!" ^| findstr /b "Index"') do set images=%%i
if %images%==5 SET ESDmulti%1=1
bin\wimlib-imagex.exe info "!ESDfile%1!" 4 >nul 2>&1
IF %ERRORLEVEL% EQU 74 SET ESDenc%1=1
goto :eof

:Dual
cls
IF EXIST ISOFOLDER\ rmdir /s /q ISOFOLDER\
mkdir ISOFOLDER
CALL :dISO 1
CALL :dISO 2
bin\7z.exe l .\ISOFOLDER\x64\sources\SetupPlatform.dll >.\bin\version.txt 2>&1
IF %ERRORLEVEL% NEQ 0 (
echo.
echo =================================================================
echo  正在读取 SetupPlatform.dll 信息时出现错误。
echo =================================================================
echo.
echo  请按任意键退出脚本。
pause >nul
exit
)
for /f "tokens=4,5 delims=. " %%i in ('"findstr /B "FileVersion" .\bin\version.txt" 2^>nul') do set version=%%i.%%j
for /f "tokens=7 delims=.) " %%i in ('"findstr /B "FileVersion" .\bin\version.txt" 2^>nul') do set datetime=%%i
for /f "tokens=6 delims=.( " %%i in ('"findstr /B "FileVersion" .\bin\version.txt" 2^>nul') do set branch=%%i
del /f /q .\bin\version.txt
for %%b in (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do set branch=!branch:%%b=%%b!
set _label=%version%.%datetime%.%branch%_CLIENT
set langid=%ESDlang1%
for %%b in (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do set langid=!langid:%%b=%%b!
set archl=X86-X64
if /i %ESDarch1%==x86 (set ESDarch1=X86) else (set ESDarch1=X64)
if /i %ESDarch2%==x86 (set ESDarch2=X86) else (set ESDarch2=X64)
if /i %DVDLABEL1% equ %DVDLABEL2% (
set DVDLABEL=%DVDLABEL1%_%archl%FRE_%langid%_DV5
set DVDISO=%_label%%DVDISO1%_%archl%FRE_%langid%.ISO
) else (
set DVDLABEL=J_CCSA_%archl%FRE_%langid%_DV5
set DVDISO=%_label%%DVDISO1%_%ESDarch1%FRE-%DVDISO2%_%ESDarch2%FRE_%langid%.ISO
)
if %combine%==0 goto :BCD
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex.exe info ISOFOLDER\x86\sources\install.wim ^| findstr /c:"Image Count"') do set imagesi=%%i
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex.exe info ISOFOLDER\x64\sources\install.wim ^| findstr /c:"Image Count"') do set imagesx=%%i
for /f "tokens=2* delims=: " %%i in ('bin\wimlib-imagex.exe info ISOFOLDER\x86\sources\install.wim 1 ^| findstr /b "Name"') do set "_osi=%%j x86"
for /f "tokens=2* delims=: " %%i in ('bin\wimlib-imagex.exe info ISOFOLDER\x64\sources\install.wim 1 ^| findstr /b "Name"') do set "_osx=%%j x64"
if %imagesi%==2 for /f "tokens=2* delims=: " %%i in ('bin\wimlib-imagex.exe info ISOFOLDER\x86\sources\install.wim 2 ^| findstr /b "Name"') do set "_osi2=%%j x86"
if %imagesx%==2 for /f "tokens=2* delims=: " %%i in ('bin\wimlib-imagex.exe info ISOFOLDER\x64\sources\install.wim 2 ^| findstr /b "Name"') do set "_osx2=%%j x64"
echo.
echo ============================================================
echo 正在统一 install.wim 文件...
echo ============================================================
echo.
echo Adjusting x86 info
"%wimlib%" info ISOFOLDER\x86\sources\install.wim 1 "%_osi%" "%_osi%"
if %imagesi%==2 "%wimlib%" info ISOFOLDER\x86\sources\install.wim 2 "%_osi2%" "%_osi2%"
echo.
echo Merging x64 image^(s^)
"%wimlib%" export ISOFOLDER\x64\sources\install.wim 1 ISOFOLDER\x86\sources\install.wim "%_osx%" "%_osx%"
if %imagesx%==2 "%wimlib%" export ISOFOLDER\x64\sources\install.wim 2 ISOFOLDER\x86\sources\install.wim "%_osx2%" "%_osx2%"
echo.
echo Replacing \x86\sources\install.wim -^> \x64\sources\install.wim
del ISOFOLDER\x64\sources\install.wim >nul 2>&1
copy /y ISOFOLDER\x86\sources\install.wim ISOFOLDER\x64\sources\install.wim

:BCD
echo.
echo ============================================================
echo 正在准备 BCD 设置...
echo ============================================================
echo.
xcopy ISOFOLDER\x64\boot\* ISOFOLDER\boot\ /cheriky >nul 2>&1
xcopy ISOFOLDER\x64\efi\* ISOFOLDER\efi\ /cheriky >nul 2>&1
copy /y ISOFOLDER\x86\efi\boot\bootia32.efi ISOFOLDER\efi\boot\bootia32.efi >nul 2>&1
for /d %%G in (bootmgr,bootmgr.efi,setup.exe) do (copy /y ISOFOLDER\x64\%%G ISOFOLDER\%%G >nul 2>&1)
(echo [AutoRun.Amd64]
echo open=x64\setup.exe
echo icon=x64\setup.exe,0
echo.
echo [AutoRun]
echo open=x86\setup.exe
echo icon=x86\setup.exe,0
echo.)>ISOFOLDER\autorun.inf
bcdedit /store ISOFOLDER\boot\bcd /set {default} description "Windows 10 Setup (64-bit)" >nul 2>&1
bcdedit /store ISOFOLDER\boot\bcd /set {default} bootmenupolicy Legacy >nul 2>&1
bcdedit /store ISOFOLDER\boot\bcd /set {default} device ramdisk=[boot]\x64\sources\winre.wim,%ramdiskoptions% >nul 2>&1
bcdedit /store ISOFOLDER\boot\bcd /set {default} osdevice ramdisk=[boot]\x64\sources\winre.wim,%ramdiskoptions% >nul 2>&1
for /f "tokens=2 delims={}" %%A in ('bcdedit /store ISOFOLDER\boot\bcd /copy {default} /d "Windows 10 Setup (32-bit)"') do set guid={%%A}
bcdedit /store ISOFOLDER\boot\bcd /set %guid% device ramdisk=[boot]\x86\sources\winre.wim,%ramdiskoptions% >nul 2>&1
bcdedit /store ISOFOLDER\boot\bcd /set %guid% osdevice ramdisk=[boot]\x86\sources\winre.wim,%ramdiskoptions% >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /set {default} description "Windows 10 Setup (64-bit)" >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /set {default} bootmenupolicy Legacy >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /set {default} device ramdisk=[boot]\x64\sources\winre.wim,%ramdiskoptions% >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /set {default} osdevice ramdisk=[boot]\x64\sources\winre.wim,%ramdiskoptions% >nul 2>&1
for /f "tokens=2 delims={}" %%A in ('bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /copy {default} /d "Windows 10 Setup (32-bit)"') do set guid={%%A}
bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /set %guid% device ramdisk=[boot]\x86\sources\winre.wim,%ramdiskoptions% >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /set %guid% osdevice ramdisk=[boot]\x86\sources\winre.wim,%ramdiskoptions% >nul 2>&1
echo.
echo ============================================================
echo  正在写入 ISO 镜像文件...
echo ============================================================
for /f "tokens=5,6,7,8,9,10 delims=: " %%G in ('bin\wimlib-imagex.exe info ISOFOLDER\x64\sources\%WIMFILE% 1 ^| find /i "Last Modification Time"') do (set mmm=%%G&set "isotime=%%H/%%L,%%I:%%J:%%K")
call :setdate %mmm%
bin\cdimage.exe -bootdata:2#p0,e,b"ISOFOLDER\boot\etfsboot.com"#pEF,e,b"ISOFOLDER\efi\Microsoft\boot\efisys.bin" -o -m -u2 -udfver102 -t%isotime% -g -l%DVDLABEL% ISOFOLDER %DVDISO%
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (
echo.
echo  在写入 ISO 镜像文件的过程中报告了一个错误。
echo.
echo  请按任意键退出脚本。
pause >nul
exit
)
rmdir /s /q ISOFOLDER\
echo.
echo  请按任意键退出脚本。
pause >nul
GOTO :QUIT

:dISO
echo.
SET ENCRYPTEDESD=!ESDfile%1!
IF !ESDenc%1!==1 CALL :DECRYPT
"%wimlib%" extract "%ENCRYPTEDESD%" 1 sources\ei.cfg --dest-dir=.\bin --no-acls >nul 2>&1
type .\bin\ei.cfg 2>nul | find /i "Volume" 1>nul && set ESDvol%1=1
del bin\ei.cfg >nul 2>&1
CALL :dPREPARE %1
echo ============================================================
echo  正在为安装镜像进行布局 ^(!ESDarch%1!^)...
echo ============================================================
echo.
"%wimlib%" apply "%ENCRYPTEDESD%" 1 ISOFOLDER\!ESDarch%1!\ >nul 2>&1
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo  在应用映像的时候报告了一个错误。&PAUSE&GOTO :QUIT)
del ISOFOLDER\!ESDarch%1!\MediaMeta.xml >nul 2>&1
echo.
echo ============================================================
echo Creating %WIMFILE% ^(!ESDarch%1!^)...
echo ============================================================
echo.
if %WIMFILE%==install.esd (
"%wimlib%" export "%ENCRYPTEDESD%" 4 ISOFOLDER\!ESDarch%1!\sources\%WIMFILE%
) else (
"%wimlib%" export "%ENCRYPTEDESD%" 4 ISOFOLDER\!ESDarch%1!\sources\%WIMFILE% --compress=maximum
)
IF !ESDmulti%1!==1 echo.&"%wimlib%" export "%ENCRYPTEDESD%" 5 ISOFOLDER\!ESDarch%1!\sources\%WIMFILE%
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo  在导出映像的时候报告了一个错误。&PAUSE&GOTO :QUIT)
echo.
echo ============================================================
echo  正在提取 winre.wim ^(!ESDarch%1!^)...
echo ============================================================
echo.
"%wimlib%" extract ISOFOLDER\!ESDarch%1!\sources\%WIMFILE% 1 Windows\System32\Recovery\winre.wim --dest-dir=.\ISOFOLDER\!ESDarch%1!\sources --no-acls
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo  在导出映像的时候报告了一个错误。&PAUSE&GOTO :QUIT)
copy /y .\bin\reagent.xml .\ISOFOLDER\!ESDarch%1!\sources >nul 2>&1
exit /b

:dPREPARE
IF !ESDmulti%1!==1 (
if /i !ESDedition%1!==Professional set DVDLABEL%1=J_CCSA&set DVDISO%1=PRO-CORE_OEMRET
if /i !ESDedition%1!==ProfessionalN set DVDLABEL%1=J_CCSNA&set DVDISO%1=PRON-COREN_OEMRET
exit /b
)
if /i !ESDedition%1!==Core set DVDLABEL%1=J_CCRA&set DVDISO%1=CORE_OEMRET
if /i !ESDedition%1!==CoreN set DVDLABEL%1=J_CCRNA&set DVDISO%1=COREN_OEMRET
if /i !ESDedition%1!==CoreSingleLanguage set DVDLABEL%1=J_CSLA&set DVDISO%1=SINGLELANGUAGE_OEM
if /i !ESDedition%1!==CoreCountrySpecific set DVDLABEL%1=J_CCHA&set DVDISO%1=CHINA_OEM
if /i !ESDedition%1!==Professional (IF !ESDvol%1!==1 (set DVDLABEL%1=J_CPRA&set DVDISO%1=PROFESSIONALVL_VOL) else (set DVDLABEL%1=J_CPRA&set DVDISO%1=PRO_OEMRET))
if /i !ESDedition%1!==ProfessionalN (IF !ESDvol%1!==1 (set DVDLABEL%1=J_CPRNA&set DVDISO%1=PROFESSIONALNVL_VOL) else (set DVDLABEL%1=J_CPRNA&set DVDISO%1=PRON_OEMRET))
if /i !ESDedition%1!==Education (IF !ESDvol%1!==1 (set DVDLABEL%1=J_CEDA&set DVDISO%1=EDUCATION_VOL) else (set DVDLABEL%1=J_CEDA&set DVDISO%1=EDUCATION_RET))
if /i !ESDedition%1!==EducationN (IF !ESDvol%1!==1 (set DVDLABEL%1=J_CEDNA&set DVDISO%1=EDUCATIONN_VOL) else (set DVDLABEL%1=J_CEDNA&set DVDISO%1=EDUCATIONN_RET))
if /i !ESDedition%1!==Enterprise set DVDLABEL%1=J_CENA&set DVDISO%1=ENTERPRISE_VOL
if /i !ESDedition%1!==EnterpriseN set DVDLABEL%1=J_CENNA&set DVDISO%1=ENTERPRISEN_VOL
if /i !ESDedition%1!==EnterpriseS set DVDLABEL%1=J_CES&set DVDISO%1=ENTERPRISES_VOL
if /i !ESDedition%1!==EnterpriseSN set DVDLABEL%1=J_CESN&set DVDISO%1=ENTERPRISESN_VOL
exit /b

:QUIT
IF EXIST ISOFOLDER\ rmdir /s /q ISOFOLDER\
IF EXIST "%ENCRYPTEDESD%.bak" (
del /f /q "%ENCRYPTEDESD%" >nul 2>&1
ren "%ENCRYPTEDESD%.bak" %ENCRYPTEDESDN%
)
exit