はじめに
Windows PE のメディアを作成するときに、一緒にアプリケーションを含める場合は、一度マウントしてコミットする必要があるので、その操作を自動で行えるように、バッチファイルのコードを作成しました。
含めるアプリケーションは自由に入れれるので、Customize のところで、アプリケーションのコピーなどのコマンドを記述しておくと、自動でWindows PEのisoを作成できます。
Code
@echo off
setlocal
net session >nul 2>&1
if errorlevel 1 (
powerShell -Command "Start-Process -Verb RunAs -FilePath '%0'"
exit /b
)
set ADK_PATH=C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\
set ADK_DEV_TOOLS_DIR=%ADK_PATH%Deployment Tools\
set ADK_WIN_PE_DIR=%ADK_PATH%Windows Preinstallation Environment\
set ADK_DEV_TOOLS_ENV_PATH=%ADK_DEV_TOOLS_DIR%DandISetEnv.bat
set PE_OUT_DIR=%~dp0.out\
set PE_TMP_DIR=%PE_OUT_DIR%win-pe\
: https://learn.microsoft.com/en-us/windows-hardware/get-started/adk-install
:
: "Download the Windows ADK" for Windows 11, version 22H2 (updated September 2023)
: "Download the Windows PE add-on" for the Windows ADK for Windows 11, version 22H2 (updated September 2023)
:
: "Download the Windows ADK" Enable Developer Tools
if not exist "%ADK_DEV_TOOLS_DIR%" (
echo Developer Tools is not installed.
goto :EXIT
)
if not exist "%ADK_WIN_PE_DIR%" (
echo Windows PE Addon is not installed.
goto :EXIT
)
echo Initialize...
Dism /Unmount-Image /MountDir:%PE_TMP_DIR%mount /Discard >nul 2>&1
if exist "%PE_OUT_DIR%" ( rmdir /s /q "%PE_OUT_DIR%" )
mkdir "%PE_OUT_DIR%"
call "%ADK_DEV_TOOLS_ENV_PATH%"
call copype amd64 "%PE_TMP_DIR%"
Dism /mount-image /ImageFile:%PE_TMP_DIR%media\sources\boot.wim /Index:1 /MountDir:%PE_TMP_DIR%mount
echo ------------------------ Customize ------------------------
: ここにアプリケーションの移動やらを記述
: .out\win-pe\mountの中に入れることで、PE起動時に含まれるようにすることができる
echo -----------------------------------------------------------
Dism /Unmount-Image /MountDir:%PE_TMP_DIR%mount /Commit
call MakeWinPEMedia /ISO %PE_TMP_DIR% %PE_OUT_DIR%windows_pe_amd64.iso
endlocal
:EXIT
pause
Reference