WimHelper/WimHelper.cmd

452 lines
19 KiB
Batchfile
Raw Normal View History

2017-11-22 08:40:21 +08:00
@echo off
rem <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ԱȨ<D4B1><C8A8>
pushd "%~dp0" && Dism 1>nul 2>nul || mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 "%*"","","runas",1)(window.close) && Exit /B 1
rem <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
color 1F
mode con cols=120
cls
setlocal EnableDelayedExpansion
set NSudo="%~dp0Bin\%PROCESSOR_ARCHITECTURE%\NSudo.exe"
2023-10-30 14:43:25 +08:00
set "Dism=Dism.exe /NoRestart /LogLevel:3 /LogPath:%~dp0Dism_%date:~0,4%%date:~5,2%%date:~8,2%.log"
2017-12-25 18:05:25 +08:00
set "SRC=%SystemDrive%"
2017-11-22 08:40:21 +08:00
set "MNT=%~dp0Mount"
set "TMP=%~dp0Temp"
set "ImagePath=%~1"
rem <20>ű<EFBFBD><C5B1><EFBFBD>ʼ
:Start
if "%ImagePath%" equ "" goto :SelectImage
if not exist "%ImagePath%" ( echo <20><><EFBFBD><EFBFBD> %ImagePath% <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> && goto :Exit )
Dism /Get-ImageInfo /ImageFile:"%ImagePath%" 1>nul 2>nul || echo <20>ļ<EFBFBD> %ImagePath% <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ľ<EFBFBD><C4BE><EFBFBD><EFBFBD>ļ<EFBFBD> && goto :Exit
title <20><><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC>
call :CleanUp
md "%TMP%" && md "%MNT%"
call :MakeWim "%ImagePath%", "%~2"
2018-04-27 16:05:16 +08:00
rem call :MakeOEM "%ImagePath%", 1
2017-11-22 08:40:21 +08:00
goto :Exit
rem ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
:SelectImage
set selectimage=mshta "about:<input type=file id=f><script>f.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(f.value);window.close();</script>"
for /f "tokens=* delims=" %%f in ('%selectimage%') do set "ImagePath=%%f"
if "%ImagePath%" equ "" goto :Exit
goto :Start
rem <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7> ]
:MakeWim
if /i "%~x1" equ ".esd" ( call :MakeESD "%~1" && goto :eof )
for /f "tokens=3" %%f in ('%Dism% /English /Get-ImageInfo /ImageFile:"%~1" ^| findstr /i Index') do ( set "ImageCount=%%f" )
for /l %%f in (1, 1, %ImageCount%) do call :MakeWimIndex "%~1", "%%f"
2017-11-22 08:40:21 +08:00
call :ImageOptimize "%~1"
goto :eof
rem <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7> ]
:MakeESD
setlocal
set "WimPath=%TMP%\%~n1_%time:~0,2%%time:~3,2%%time:~5,2%.wim"
%Dism% /Export-Image /SourceImageFile:"%~1" /All /DestinationImageFile:"%WimPath%" /Compress:max
call :MakeWim "%WimPath%"
rem <20><><EFBFBD><EFBFBD>ΪESD<53><44><EFBFBD><EFBFBD>
call :RemoveFile "%~1"
%Dism% /Export-Image /SourceImageFile:"%WimPath%" /All /DestinationImageFile:"%~1" /Compress:recovery
2017-11-22 08:40:21 +08:00
call :RemoveFile "%WimPath%"
endlocal
goto :eof
rem <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>, %~2 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ]
2017-11-22 08:40:21 +08:00
:MakeWimIndex
call :GetImageInfo "%~1", "%~2"
2017-11-22 08:40:21 +08:00
title <20><><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD> [%~2] <20><><EFBFBD><EFBFBD> %ImageName% <20>%ImageVersion% <20><><EFBFBD><EFBFBD> %ImageLanguage%
%Dism% /Mount-Wim /WimFile:"%~1" /Index:%~2 /MountDir:"%MNT%"
2018-01-25 13:25:18 +08:00
call :MakeWimClean "%MNT%"
2017-11-22 08:40:21 +08:00
goto :eof
rem <20><><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD><E6BEB5> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7> ]
:MakeWimClean
call :RemoveAppx "%~1"
2019-05-02 19:47:41 +08:00
for /f %%f in ('type "%~dp0Pack\FeatureList.%ImageShortVersion%.txt" 2^>nul') do call :RemoveCapability "%~1", "%%f"
for /f %%f in ('type "%~dp0Pack\RemoveList.%ImageVersion%.txt" 2^>nul') do call :RemoveComponent "%~1", "%%f"
2021-07-29 00:38:58 +08:00
rem call :IntRollupFix "%~1"
rem call :AddAppx "%~1", "DesktopAppInstaller", "VCLibs"
2023-10-30 14:43:25 +08:00
call :AddAppx "%~1", "WindowsStore", "VCLibs UI.Xaml.2.8 Native.Runtime Native.Framework"
call :AddAppx "%~1", "DesktopAppInstaller", "UI.Xaml.2.7"
2022-10-21 14:37:35 +08:00
if "%ImageVersion%" geq "10.0.22000" (
call :AddAppx "%~1", "WindowsTerminal"
2024-09-18 21:15:42 +08:00
call :AddAppx "%~1", "Client.WebExperience", "AppRuntime"
2023-10-30 14:43:25 +08:00
call :AddAppx "%~1", "WindowsNotepad"
2022-10-21 14:37:35 +08:00
)
call :ImportOptimize "%~1"
call :ImportUnattend "%~1"
2021-07-29 00:38:58 +08:00
call :ImageClean "%MNT%"
2019-09-01 15:14:56 +08:00
%Dism% /Unmount-Wim /MountDir:"%~1" /Commit
goto :eof
2018-04-27 16:05:16 +08:00
rem <20><><EFBFBD><EFBFBD>OEM<45><4D><EFBFBD><EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>, %~2 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ]
:MakeOEM
call :GetImageInfo "%~1", "%~2"
title <20><><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD> [%~2] <20><><EFBFBD><EFBFBD> %ImageName% <20>%ImageVersion% <20><><EFBFBD><EFBFBD> %ImageLanguage%
%Dism% /Mount-Wim /WimFile:"%~1" /Index:%~2 /MountDir:"%MNT%"
2019-05-02 19:47:41 +08:00
call :RemoveAppx "%MNT%"
2023-10-30 14:43:25 +08:00
rem for /d %%x in ("%MNT%\Program Files\WindowsApps\Microsoft.*") do call :RemoveFolder "%%x"
call :AddAppx "%MNT%", "WindowsStore", "VCLibs UI.Xaml.2.8 Native.Runtime Native.Framework"
call :AddAppx "%MNT%", "DesktopAppInstaller", "UI.Xaml.2.7"
2022-10-21 14:37:35 +08:00
if "%ImageVersion%" geq "10.0.22000" (
2023-10-30 14:43:25 +08:00
call :AddAppx "%MNT%", "WindowsTerminal"
call :AddAppx "%MNT%", "WindowsNotepad"
2022-10-21 14:37:35 +08:00
)
2019-05-02 19:47:41 +08:00
call :ImportOptimize "%MNT%"
2022-10-21 14:37:35 +08:00
call :ImportUnattend "%MNT%"
2018-04-27 16:05:16 +08:00
if exist "%~dp0Driver" %Dism% /Image:"%MNT%" /Add-Driver /Driver:"%~dp0Driver" /recurse /ForceUnsigned
call :ImageClean "%MNT%"
2019-05-02 19:47:41 +08:00
%Dism% /Unmount-Wim /MountDir:"%MNT%" /Commit
2018-04-27 16:05:16 +08:00
goto :eof
rem <20><><EFBFBD><EFBFBD>lopatkin<69><6E><EFBFBD><EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7> ]
:lopatkin
2017-11-22 08:40:21 +08:00
rem <20>޸<EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD>û<EFBFBD>ͷ<EFBFBD><CDB7>
2017-12-25 18:05:25 +08:00
xcopy /E /I /H /R /Y /J "%SRC%\ProgramData\Microsoft\User Account Pictures\*.*" "%~1\ProgramData\Microsoft\User Account Pictures" >nul
2019-05-27 22:55:37 +08:00
call :MountImageRegistry "%~1"
2017-11-22 08:40:21 +08:00
rem <20>޸<EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
call :RemoveFolder "%~1\Windows\Web\Wallpaper\Theme1"
call :RemoveFile "%~1\Windows\Resources\Themes\Theme1.theme"
2019-05-27 22:55:37 +08:00
move "%~1\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\<5C><><EFBFBD>ѧݧ<D1A7><DDA7>ܧ<EFBFBD><DCA7>ݧ<EFBFBD><DDA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.lnk" "%~1\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Calculator.lnk"
notepad "%~1\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\desktop.ini"
2017-11-22 08:40:21 +08:00
reg add "HKLM\TK_SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\LastTheme" /v "ThemeFile" /t REG_EXPAND_SZ /d "%%SystemRoot%%\Resources\Themes\Aero.theme" /f >nul
rem <20>޸<EFBFBD><DEB8><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӣ<EFBFBD><D3A2>
for /f "tokens=2 delims=@," %%j in ('reg query "HKLM\TK_SYSTEM\ControlSet001\Control\Class" /v "ClassDesc" /s ^| findstr /i inf') do (
2018-01-15 11:25:28 +08:00
for %%i in (System32\DriverStore\%ImageLanguage% INF) do (
2017-12-25 18:05:25 +08:00
for %%f in (%SRC%\Windows\%%i\%%j*) do %NSudo% cmd.exe /c copy /Y "%%f" "%~1\Windows\%%i\%%~nxf"
2017-11-22 08:40:21 +08:00
)
)
call :UnMountImageRegistry
2020-05-28 13:41:19 +08:00
if "%ImageShortVersion%" equ "10.0" (
call :RemoveAppx "%~1"
call :AddAppx "%MNT%", "DesktopAppInstaller", "VCLibs"
call :AddAppx "%MNT%", "Store", "Runtime Framework"
)
2017-12-25 18:05:25 +08:00
call :RemoveFolder "%~1\Program Files (x86)\Trey"
call :RemoveFolder "%~1\Program Files\Trey"
2018-01-15 11:25:28 +08:00
call :RemoveFile "%~1\Users\Default\Desktop\Green Christmas Tree.lnk"
2017-12-25 18:05:25 +08:00
call :RemoveFile "%~1\Windows\KEY_Aquarium-Screensavers.txt"
call :RemoveFile "%~1\Windows\System32\MA2_6.scr"
call :ImportOptimize "%~1"
2018-01-15 11:25:28 +08:00
call :ImportUnattend "%~1"
call :ImageClean "%~1"
%Dism% /Unmount-Wim /MountDir:"%~1" /Commit
2017-11-22 08:40:21 +08:00
goto :eof
rem ############################################################################################
rem <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
rem ############################################################################################
rem <20><><EFBFBD>ɻ<EFBFBD><C9BB>۸<EFBFBD><DBB8><EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7> ]
:IntRollupFix
setlocal
set "UpdatePath=%~dp0Pack\Update\%ImageVersion%.%ImageArch%"
if exist "%UpdatePath%" (
%Dism% /Image:"%~1" /Add-Package /ScratchDir:"%TMP%" /PackagePath:"%UpdatePath%"
)
set "RollupPath=%~dp0Pack\RollupFix\%ImageVersion%.%ImageArch%"
if exist "%RollupPath%" (
%Dism% /Image:"%~1" /Add-Package /ScratchDir:"%TMP%" /PackagePath:"%RollupPath%"
call :IntRecovery "%~1", "%RollupPath%"
)
2019-04-18 17:44:42 +08:00
if not exist "%~1\Windows\WinSxS\pending.xml" (
rem Enable DISM Image Cleanup with Full ResetBase...
call :MountImageRegistry "%~1"
2019-06-01 14:08:15 +08:00
Reg add "HKLM\TK_SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide\Configuration" /v "DisableComponentBackups" /t REG_DWORD /d "1" /f >nul
2019-04-18 17:44:42 +08:00
Reg add "HKLM\TK_SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide\Configuration" /v "SupersededActions" /t REG_DWORD /d "1" /f >nul
call :UnMountImageRegistry
%Dism% /Image:"%~1" /Cleanup-Image /ScratchDir:"%TMP%" /StartComponentCleanup
) else (
%NSudo% cmd.exe /c del /q "%~1\Windows\WinSxS\ManifestCache\*.bin"
%NSudo% cmd.exe /c rd /s /q "%~1\Windows\WinSxS\Temp\PendingDeletes"
%NSudo% cmd.exe /c rd /s /q "%~1\Windows\WinSxS\Temp\TransformerRollbackData"
%NSudo% cmd.exe /c rd /s /q "%~1\Windows\CbsTemp"
)
2017-11-22 08:40:21 +08:00
endlocal
goto :eof
rem <20><> WinRe <20><><EFBFBD>ɸ<EFBFBD><C9B8><EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>, %~2 <20><><EFBFBD>°<EFBFBD>·<EFBFBD><C2B7> ]
:IntRecovery
setlocal
set "WinrePath=%TMP%\Winre.%ImageVersion%.%ImageArch%.wim"
if not exist "%WinrePath%" (
call :RemoveFolder "%TMP%\RE"
md "%TMP%\RE"
echo.<2E><><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD> [%WinrePath%]
%Dism% /Mount-Wim /WimFile:"%~1\Windows\System32\Recovery\Winre.wim" /Index:1 /MountDir:"%TMP%\RE" /Quiet
call :MountImageRegistry "%TMP%\RE"
rem Enable DISM Image Cleanup with Full ResetBase...
2019-06-01 14:08:15 +08:00
Reg add "HKLM\TK_SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide\Configuration" /v "DisableComponentBackups" /t REG_DWORD /d "1" /f >nul
2017-11-22 08:40:21 +08:00
call :UnMountImageRegistry
echo.<2E><><EFBFBD>ɸ<EFBFBD><C9B8><EFBFBD> [%WinrePath%]
%Dism% /Image:"%TMP%\RE" /Add-Package /ScratchDir:"%TMP%" /PackagePath:"%~2" /Quiet
%Dism% /Image:"%TMP%\RE" /Cleanup-Image /ScratchDir:"%TMP%" /StartComponentCleanup /ResetBase /Quiet
call :ImageClean "%TMP%\RE"
echo.<2E><><EFBFBD><EFBFBD><E6BEB5> [%WinrePath%]
%Dism% /Unmount-Wim /MountDir:"%TMP%\RE" /Commit /Quiet
echo.<2E>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD> [%WinrePath%]
%Dism% /Export-Image /SourceImageFile:"%~1\Windows\System32\Recovery\Winre.wim" /All /DestinationImageFile:"%WinrePath%" /Compress:max /Quiet
2017-11-22 08:40:21 +08:00
)
copy /Y "%WinrePath%" "%~1\Windows\System32\Recovery\Winre.wim" >nul
endlocal
goto :eof
rem <20><><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>, %~2 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ]
:IntFeature
setlocal
set "FeaturePath=%~dp0Pack\%~2\%ImageVersion%.%ImageArch%"
if not exist "%FeaturePath%" ( echo<>ҵ<EFBFBD> %FeaturePath% && goto :eof )
%Dism% /Image:"%~1" /Get-FeatureInfo /FeatureName:%~2 | findstr /c:"State : Enable Pending" >nul
if errorlevel 1 (
echo.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [%~2]
%Dism% /Image:"%~1" /Enable-Feature /All /LimitAccess /FeatureName:%~2 /Source:"%FeaturePath%" /Quiet
) else ( echo.<2E><><EFBFBD><EFBFBD> [%~2] <20>ѿ<EFBFBD><D1BF><EFBFBD> )
endlocal
goto :eof
rem <20><><EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7> ]
:ImportOptimize
call :MountImageRegistry "%~1"
call :ImportRegistry "%~dp0Pack\Optimize\%ImageShortVersion%.reg"
call :ImportRegistry "%~dp0Pack\Optimize\%ImageShortVersion%.%ImageArch%.reg"
if "%ImageType%" equ "Server" call :ImportRegistry "%~dp0Pack\Optimize\Server.reg"
if "%ImageShortVersion%" equ "10.0" (
rem Removing Windows Mixed Reality Menu from Settings App
Reg add "HKLM\TK_NTUSER\Software\Microsoft\Windows\CurrentVersion\Holographic" /v "FirstRunSucceeded" /t REG_DWORD /d "0" /f >nul
2017-11-29 13:43:09 +08:00
rem <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƭ<EFBFBD><EFBFBD><E9BFB4>, ɾ<><C9BE> 3D<33><44>ͼ <20>Ҽ<EFBFBD>
Reg add "HKLM\TK_SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities" /v "ApplicationDescription" /t REG_SZ /d "@%%ProgramFiles%%\Windows Photo Viewer\photoviewer.dll,-3069" /f >nul
Reg add "HKLM\TK_SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities" /v "ApplicationName" /t REG_SZ /d "@%%ProgramFiles%%\Windows Photo Viewer\photoviewer.dll,-3009" /f >nul
for %%t in (.bmp .gif .jfif .ico .jpe .jpeg .jpg .png .tif .tiff) do (
Reg add "HKLM\TK_SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" /v "%%t" /t REG_SZ /d "PhotoViewer.FileAssoc.Tiff" /f >nul
Reg add "HKLM\TK_SOFTWARE\Classes\%%t" /ve /t REG_SZ /d "PhotoViewer.FileAssoc.Tiff" /f >nul 2>&1
Reg delete "HKLM\TK_SOFTWARE\Classes\SystemFileAssociations\%%t\Shell\3D Edit" /f >nul 2>&1
)
rem <20>ӳٹ<D3B3><D9B9>ܸ<EFBFBD><DCB8><EFBFBD>
2018-11-08 12:03:37 +08:00
if "%ImageVersion%" leq "10.0.17134" Reg add "HKLM\TK_SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v "DeferFeatureUpdatesPeriodInDays" /t REG_DWORD /d "365" /f >nul
rem <20>Ҽ<EFBFBD><D2BC>˵<EFBFBD><CBB5>Ż<EFBFBD>
2017-11-22 08:40:21 +08:00
call :ImportRegistry "%~dp0Pack\Optimize\Context.reg"
2021-07-29 00:38:58 +08:00
if "%ImageVersion%" lss "10.0.22000" (
2022-10-21 14:37:35 +08:00
call :ImportStartLayout "%~1", "LayoutModification.xml"
2021-07-29 00:38:58 +08:00
) else (
2022-10-21 14:37:35 +08:00
call :ImportStartLayout "%~1", "LayoutModification.json"
call :ImportRegistry "%~dp0Pack\Optimize\11.0.reg"
2021-07-29 00:38:58 +08:00
)
2017-11-22 08:40:21 +08:00
)
call :UnMountImageRegistry
goto :eof
rem <20><><EFBFBD>ɶ<EFBFBD><C9B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>, %~2 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ]
:IntExtra
echo.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [%~2]
setlocal
set "ExtraPath=%~dp0Pack\Extra\%~2"
if "%ImageArch%"=="x86" set "PackageIndex=1"
if "%ImageArch%"=="x64" set "PackageIndex=2"
if exist "%ExtraPath%.tpk" (
%Dism% /Apply-Image /ImageFile:"%ExtraPath%.tpk" /Index:%PackageIndex% /ApplyDir:"%~1" /CheckIntegrity /Verify /Quiet
)
if exist "%ExtraPath%.%ImageLanguage%.tpk" (
%Dism% /Apply-Image /ImageFile:"%ExtraPath%.%ImageLanguage%.tpk" /Index:%PackageIndex% /ApplyDir:"%~1" /CheckIntegrity /Verify /Quiet
)
2018-04-17 18:17:39 +08:00
rem if exist "%ExtraPath%.%ImageArch%.reg" (
rem call :MountImageRegistry "%~1"
rem call :ImportRegistry "%ExtraPath%.%ImageArch%.reg"
rem call :UnMountImageRegistry
rem )
2017-11-22 08:40:21 +08:00
if exist "%ExtraPath%.cmd" call %ExtraPath%.cmd "%~1" %ImageArch% %ImageLanguage%
endlocal
goto :eof
rem ############################################################################################
rem <20><><EFBFBD>ߺ<EFBFBD><DFBA><EFBFBD>
rem ############################################################################################
rem <20><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>ļ<EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>, %~2 : Ӧ<><D3A6><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>(Admin, Audit) ]
:ImportUnattend
call :RemoveFolder "%~1\Windows\Setup\Scripts"
md "%~1\Windows\Setup\Scripts"
xcopy /E /I /H /R /Y /J "%~dp0Pack\Scripts\*.*" "%~1\Windows\Setup\Scripts" >nul
setlocal
if /i "%~2" equ "Admin" (
if exist "%~dp0Pack\AAct_%ImageArch%.exe" copy "%~dp0Pack\AAct_%ImageArch%.exe" "%~1\Windows\Setup\Scripts\AAct.exe" >nul
set "UnattendFile=%~dp0Pack\Unattend.Admin.xml"
2018-11-08 12:03:37 +08:00
if "%ImageShortVersion%" leq "10.0" (
2017-11-22 08:40:21 +08:00
call :MountImageRegistry "%~1"
Reg add "HKLM\TK_SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v "FilterAdministratorToken" /t REG_DWORD /d 1 /f >nul
call :UnMountImageRegistry
2018-11-08 12:03:37 +08:00
)
2018-04-27 16:05:16 +08:00
) else if /i "%~2" equ "OEM" (
set "UnattendFile=%~dp0Pack\Unattend.OEM.xml"
copy "%~dp0Pack\oemlogo.bmp" "%~1\Windows\System32\oemlogo.bmp"
2017-11-22 08:40:21 +08:00
) else (
2023-10-30 14:43:25 +08:00
set "UnattendFile=%~dp0Pack\Unattend.%ImageShortVersion%.%ImageArch%.xml"
2017-11-22 08:40:21 +08:00
)
if exist "%UnattendFile%" (
echo.<2E><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6> [%UnattendFile%]
2017-11-29 13:43:09 +08:00
call :RemoveFolder "%~1\Windows\Panther"
md "%~1\Windows\Panther"
2017-11-22 08:40:21 +08:00
copy /Y "%UnattendFile%" "%~1\Windows\Panther\unattend.xml" >nul
)
endlocal
goto :eof
rem <20><><EFBFBD>ʼ<EBBFAA>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>, %~2 <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7> ]
:ImportStartLayout
2021-07-29 00:38:58 +08:00
copy /y "%~dp0Pack\%~2" "%~1\Users\Default\AppData\Local\Microsoft\Windows\Shell\%~2" >nul
2017-11-22 08:40:21 +08:00
call :RemoveFile "%~1\Users\Default\AppData\Local\TileDataLayer"
goto :eof
rem <20><><EFBFBD><EFBFBD>AppxӦ<78><D3A6> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>, %~2 : Ӧ<>ð<EFBFBD><C3B0><EFBFBD>, %~3 : Ӧ<><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ]
:AddAppx
setlocal
set "Apps=%~dp0Pack\Appx"
set LicPath=/SkipLicense
if "%ImageArch%" equ "x86" ( set "AppxArch=*x86*" ) else ( set "AppxArch=*" )
for /f %%f in ('"dir /b %Apps%\*%~2*.xml" 2^>nul') do ( set LicPath=/LicensePath:"%Apps%\%%f" )
for %%j in (%~3) do for /f %%i in ('"dir /b %Apps%\*%%j%AppxArch%.appx" 2^>nul') do ( set Dependency=!Dependency! /DependencyPackagePath:"%Apps%\%%i" )
2023-04-14 13:54:15 +08:00
for %%j in (%~3) do for /f %%i in ('"dir /b %Apps%\*%%j%AppxArch%.msix" 2^>nul') do ( set Dependency=!Dependency! /DependencyPackagePath:"%Apps%\%%i" )
2021-07-29 00:38:58 +08:00
for /f %%i in ('"dir /b %Apps%\*%~2*.*xbundle" 2^>nul') do (
2017-11-22 08:40:21 +08:00
echo.<2E><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6> [%%~ni]
%Dism% /Image:"%~1" /Add-ProvisionedAppxPackage /PackagePath:"%Apps%\%%i" %LicPath% %Dependency% /Quiet
)
endlocal
goto :eof
2019-05-02 19:47:41 +08:00
rem <20><><EFBFBD>ù<EFBFBD><C3B9><EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>, %~2 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ]
:RemoveFeature
for /f "tokens=4" %%f in ('%Dism% /English /Image:"%~1" /Get-Features ^| findstr Feature ^| findstr /i "%~2"') do (
echo.<2E>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD> [%%f]
%Dism% /Image:"%~1" /Disable-Feature /FeatureName:"%%f" /Remove
)
goto :eof
2017-11-22 08:40:21 +08:00
rem <20>Ƴ<EFBFBD><C6B3>Դ<EFBFBD>Ӧ<EFBFBD><D3A6> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7> ]
:RemoveAppx
2023-10-30 14:43:25 +08:00
for /f "tokens=3" %%f in ('%Dism% /English /Image:"%~1" /Get-ProvisionedAppxPackages ^| findstr PackageName ^| findstr /V DesktopAppInstaller') do (
2017-11-22 08:40:21 +08:00
echo.<2E>Ƴ<EFBFBD>Ӧ<EFBFBD><D3A6> [%%f]
%Dism% /Image:"%~1" /Remove-ProvisionedAppxPackage /PackageName:"%%f" /Quiet
)
2018-04-27 09:57:32 +08:00
goto :eof
rem <20>Ƴ<EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>, %~2 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ]
:RemoveCapability
for /f "tokens=4" %%f in ('%Dism% /English /Image:"%~1" /Get-Capabilities ^| findstr Capability ^| findstr /i "%~2"') do (
echo.<2E>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD> [%%f]
%Dism% /Image:"%~1" /Remove-Capability /CapabilityName:"%%f" /Quiet
)
2017-11-22 08:40:21 +08:00
goto :eof
rem <20>Ƴ<EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>, %~2 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ]
:RemoveComponent
setlocal
rem <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
call :MountImageRegistry "%~1"
2018-04-11 10:22:45 +08:00
for /f "tokens=* delims=" %%f in ('reg query "HKLM\TK_SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages" /f "%~2" ^| findstr /i "%~2"') do (
%NSudo% reg add "%%f" /v Visibility /t REG_DWORD /d 1 /f
%NSudo% reg add "%%f" /v DefVis /t REG_DWORD /d 2 /f
%NSudo% reg delete "%%f\Owners" /f
2017-11-22 08:40:21 +08:00
)
call :UnMountImageRegistry
2018-04-26 18:29:17 +08:00
for /f "tokens=3 delims=: " %%f in ('%Dism% /English /Image:"%~1" /Get-Packages ^| findstr /i "%~2" ^| findstr /v %ImageLanguage%') do (
2018-04-11 10:22:45 +08:00
echo.<2E>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD> [%%f]
%Dism% /Image:"%~1" /Remove-Package /PackageName:"%%f" /Quiet
2017-11-22 08:40:21 +08:00
)
endlocal
goto :eof
rem <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD> [ %~1 : ע<><D7A2><EFBFBD><EFBFBD>·<EFBFBD><C2B7> ]
:ImportRegistry
if not exist "%~1" goto :eof
call :RemoveFile "%TMP%\%~nx1"
rem <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
for /f "delims=" %%f in ('type "%~1"') do (
set str=%%f
set "str=!str:HKEY_CURRENT_USER=HKEY_LOCAL_MACHINE\TK_NTUSER!"
set "str=!str:HKEY_LOCAL_MACHINE\SOFTWARE=HKEY_LOCAL_MACHINE\TK_SOFTWARE!"
set "str=!str:HKEY_LOCAL_MACHINE\SYSTEM=HKEY_LOCAL_MACHINE\TK_SYSTEM!"
2018-12-28 10:09:18 +08:00
set "str=!str:CurrentControlSet=ControlSet001!"
2017-11-22 08:40:21 +08:00
echo !str!>>"%TMP%\%~nx1"
)
2018-04-27 08:53:22 +08:00
%NSudo% reg import "%TMP%\%~nx1" >nul 2>&1
2017-11-22 08:40:21 +08:00
goto :eof
rem <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7> ]
:MountImageRegistry
reg load HKLM\TK_NTUSER "%~1\Users\Default\ntuser.dat" >nul
reg load HKLM\TK_SOFTWARE "%~1\Windows\System32\config\SOFTWARE" >nul
reg load HKLM\TK_SYSTEM "%~1\Windows\System32\config\SYSTEM" >nul
goto :eof
rem ж<><D0B6>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
:UnMountImageRegistry
reg unload HKLM\TK_NTUSER >nul 2>&1
reg unload HKLM\TK_SOFTWARE >nul 2>&1
reg unload HKLM\TK_SYSTEM >nul 2>&1
goto :eof
rem <20><><EFBFBD><EFBFBD><E6BEB5> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7> ]
:ImageClean
rd /s /q "%~1\Users\Administrator" >nul 2>&1
rd /s /q "%~1\Program Files\Classic Shell" >nul 2>&1
rd /s /q "%~1\Recovery" >nul 2>&1
rd /s /q "%~1\$RECYCLE.BIN" >nul 2>&1
rd /s /q "%~1\Logs" >nul 2>&1
del /q "%~1\Windows\INF\*.pnf" >nul 2>&1
del /s /q "%~1\*.log" >nul 2>&1
del /s /q /a:h "%~1\*.log" >nul 2>&1
del /s /q /a:h "%~1\*.blf" >nul 2>&1
del /s /q /a:h "%~1\*.regtrans-ms" >nul 2>&1
goto :eof
rem <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>, %~2 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ]
:GetImageInfo
for /f "tokens=2 delims=:" %%f in ('%Dism% /English /Get-ImageInfo /ImageFile:"%~1" /Index:%~2 ^| findstr /i Name') do ( set "ImageName=%%f" )
for /f "tokens=3" %%f in ('%Dism% /English /Get-ImageInfo /ImageFile:"%~1" /Index:%~2 ^| findstr /i Architecture') do ( set "ImageArch=%%f" )
for /f "tokens=3" %%f in ('%Dism% /English /Get-ImageInfo /ImageFile:"%~1" /Index:%~2 ^| findstr /i Version') do ( set "ImageVersion=%%f" )
for /f "tokens=3" %%f in ('%Dism% /English /Get-ImageInfo /ImageFile:"%~1" /Index:%~2 ^| findstr /i Edition') do ( set "ImageEdition=%%f" )
for /f "tokens=3" %%f in ('%Dism% /English /Get-ImageInfo /ImageFile:"%~1" /Index:%~2 ^| findstr /i Installation') do ( set "ImageType=%%f" )
for /f "tokens=* delims=" %%f in ('%Dism% /English /Get-ImageInfo /ImageFile:"%~1" /Index:%~2 ^| findstr /i Default') do ( set "ImageLanguage=%%f" && set "ImageLanguage=!ImageLanguage:~1,-10!" )
2017-11-22 08:40:21 +08:00
for /f "tokens=1,2 delims=." %%f in ('echo %ImageVersion%') do ( set "ImageShortVersion=%%f.%%g" )
goto :eof
rem <20>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD> [ %~1 : <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7> ]
:ImageOptimize
title <20><><EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD> %~1
if not exist "%TMP%\%~nx1" %Dism% /Export-Image /SourceImageFile:"%~1" /All /DestinationImageFile:"%TMP%\%~nx1" /CheckIntegrity /Compress:max
move /Y "%TMP%\%~nx1" "%~1" >nul
goto :eof
rem <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
:CleanUp
call :UnMountImageRegistry
if exist "%MNT%\Windows" ( %Dism% /Unmount-Wim /MountDir:"%MNT%" /ScratchDir:"%TMP%" /Discard /Quiet )
if exist "%TMP%\RE\Windows" ( %Dism% /Unmount-Wim /MountDir:"%TMP%\RE" /ScratchDir:"%TMP%" /Discard /Quiet )
2017-11-22 08:40:21 +08:00
call :RemoveFolder "%TMP%"
call :RemoveFolder "%MNT%"
if errorlevel 0 goto :eof
goto :Exit
rem ɾ<><C9BE><EFBFBD>ļ<EFBFBD> [ %~1 : <20>ļ<EFBFBD>·<EFBFBD><C2B7> ]
:RemoveFile
2017-12-25 18:05:25 +08:00
if exist "%~1" %NSudo% cmd.exe /c del /f /q "%~1"
2017-11-22 08:40:21 +08:00
goto :eof
rem ɾ<><C9BE>Ŀ¼ [ %~1 : Ŀ¼·<C2BC><C2B7> ]
:RemoveFolder
2017-12-25 18:05:25 +08:00
if exist "%~1" %NSudo% cmd.exe /c rd /q /s "%~1"
2017-11-22 08:40:21 +08:00
goto :eof
:Exit
call :CleanUp
endlocal EnableDelayedExpansion
title <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>