Skip to content

Instantly share code, notes, and snippets.

@hirosof
Created April 4, 2025 04:09
Show Gist options
  • Save hirosof/38751396f81bb158beda0c4bc4342258 to your computer and use it in GitHub Desktop.
Save hirosof/38751396f81bb158beda0c4bc4342258 to your computer and use it in GitHub Desktop.
@echo off
setlocal
set timebase=%time: =0%
set TimeStr=%timebase:~0,2%%timebase:~3,2%%timebase:~6,2%
set DateStr=%date:~0,4%%date:~5,2%%date:~8,2%
set EnvironmentBaseName=WindowsPE-amd64
set TargetBaseName=%EnvironmentBaseName%-%DateStr%%TimeStr%
set WorkingName=Working
rem set WorkingBaseDir=%~dp0%WorkingName%
set WorkingBaseDir=%cd%\%WorkingName%
set WorkingDir=%WorkingBaseDir%\%TargetBaseName%
set WorkingMediaDir=%WorkingDir%\media
set BootWimDir=%WorkingMediaDir%\sources\boot.wim
set WorkingMountDir=%WorkingDir%\mount
set OutputISOImage=%WorkingDir%\%TargetBaseName%.iso
set DISM_PRIMARYLOG_FILENAME_PREFIX=DISM-LOG-
set DISM_SECONDARYLOG_FILENAME_PREFIX=DISM-LOG2-
set DismLogPath=%WorkingDir%\%DISM_PRIMARYLOG_FILENAME_PREFIX%%TargetBaseName%.log
set DismLogLevel=1
set DismSecondaryLogPath=%WorkingDir%\%DISM_SECONDARYLOG_FILENAME_PREFIX%%TargetBaseName%.log
set Separator=--------------------------------------------------------------------------
set ADK_PackagePath=%WinPERootNoArch%\amd64\WinPE_OCs
set LANG_INNER_NAME=ja-jp
set LANG_DISPLAYNAME_NAME=日本語
set LANG_KEYBOARD_AND_LOCALE=0411:{03B5835F-F03C-411B-9CE2-AA23E1171E36}{A76C93D9-5523-4E90-AAFA-4DB112F9AC76}
set LANG_LAYERDRIVER=6
set TIME_ZONE_ID=Tokyo Standard Time
set ADK_PackagePath_LANG=%ADK_PackagePath%\%LANG_INNER_NAME%
echo.
echo %Separator%
echo 作業ディレクトリ:
echo %WorkingDir%
echo %Separator%
@rem WindowsPE環境(amd64)を作業フォルダにコピー
echo.
echo %Separator%
echo WindowsPEイメージをWindows ADKからコピーします。
echo %Separator%
start /wait /B cmd /c copype amd64 "%WorkingDir%"
@rem WindowsPE環境をマウント
echo.
echo %Separator%
echo WindowsPEイメージをマウントします。
echo %Separator%
start /wait /B cmd /c dism /Mount-Image /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /ImageFile:"%BootWimDir%" /Index:1 /MountDir:"%WorkingMountDir%"
echo.
echo %Separator%
echo WindowsPEに追加パッケージのインストールを行っています。
echo %Separator%
start /wait /B cmd /c dism /Add-Package /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /image:"%WorkingMountDir%" /PackagePath:"%ADK_PackagePath%\WinPE-HTA.cab"
start /wait /B cmd /c dism /Add-Package /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /image:"%WorkingMountDir%" /PackagePath:"%ADK_PackagePath%\WinPE-WMI.cab"
start /wait /B cmd /c dism /Add-Package /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /image:"%WorkingMountDir%" /PackagePath:"%ADK_PackagePath%\WinPE-NetFx.cab"
start /wait /B cmd /c dism /Add-Package /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /image:"%WorkingMountDir%" /PackagePath:"%ADK_PackagePath%\WinPE-Scripting.cab"
start /wait /B cmd /c dism /Add-Package /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /image:"%WorkingMountDir%" /PackagePath:"%ADK_PackagePath%\WinPE-PowerShell.cab"
start /wait /B cmd /c dism /Add-Package /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /image:"%WorkingMountDir%" /PackagePath:"%ADK_PackagePath_LANG%\lp.cab"
start /wait /B cmd /c dism /Add-Package /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /image:"%WorkingMountDir%" /PackagePath:"%ADK_PackagePath%\WinPE-FontSupport-%LANG_INNER_NAME%.cab"
start /wait /B cmd /c dism /Add-Package /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /image:"%WorkingMountDir%" /PackagePath:"%ADK_PackagePath_LANG%\WinPE-HTA_%LANG_INNER_NAME%.cab"
start /wait /B cmd /c dism /Add-Package /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /image:"%WorkingMountDir%" /PackagePath:"%ADK_PackagePath_LANG%\WinPE-WMI_%LANG_INNER_NAME%.cab"
start /wait /B cmd /c dism /Add-Package /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /image:"%WorkingMountDir%" /PackagePath:"%ADK_PackagePath_LANG%\WinPE-NetFx_%LANG_INNER_NAME%.cab"
start /wait /B cmd /c dism /Add-Package /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /image:"%WorkingMountDir%" /PackagePath:"%ADK_PackagePath_LANG%\WinPE-Scripting_%LANG_INNER_NAME%.cab"
start /wait /B cmd /c dism /Add-Package /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /image:"%WorkingMountDir%" /PackagePath:"%ADK_PackagePath_LANG%\WinPE-PowerShell_%LANG_INNER_NAME%.cab"
echo.
echo.
echo %Separator%
echo WindowsPEの言語設定(%LANG_DISPLAYNAME_NAME%)や環境設定を行っています。
echo %Separator%
start /wait /B cmd /c dism /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /Image:"%WorkingMountDir%" /Set-AllIntl:"%LANG_INNER_NAME%"
start /wait /B cmd /c dism /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /Image:"%WorkingMountDir%" /Set-InputLocale:"%LANG_KEYBOARD_AND_LOCALE%"
start /wait /B cmd /c dism /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /Image:"%WorkingMountDir%" /Set-LayeredDriver:"%LANG_LAYERDRIVER%"
start /wait /B cmd /c dism /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /Image:"%WorkingMountDir%" /Set-Timezone:"%TIME_ZONE_ID%"
echo.
echo.
echo %Separator%
echo 必要な設定が完了しました。WindowsPEに行った変更を保存しています。
echo %Separator%
@rem WindowsPE環境の変更を適用する
start /wait /B cmd /c dism /Commit-Wim /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /MountDir:"%WorkingMountDir%"
echo.
echo %Separator%
echo WindowsPEの環境のパッケージ情報を出力します。
echo %Separator%
start /wait /B cmd /c dism /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /Format:Table /Get-Packages /image:"%WorkingMountDir%"
echo.
echo %Separator%
echo WindowsPEの環境情報を出力します。
echo %Separator%
start /wait /B cmd /c dism /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /Get-Intl /image:"%WorkingMountDir%"
echo.
echo.
echo %Separator%
echo WindowsPEのイメージの内容を追加で変更しますか?
echo %Separator%
choice /c YN
if %errorlevel%==2 goto :SKIP_USER_EDIT
echo.
echo %Separator%
echo 次のフォルダにあるWindowsPEのイメージの内容を追加で変更してください。
echo %WorkingMountDir%
echo.
:USER_EDIT_MODE
echo 【編集メニュー】 次から選択してください。
echo    E:エクスプローラーでフォルダーを開く
echo    S:変更を保存する
echo    D:変更を破棄する
echo.
choice /c ESD
echo.
if %errorlevel%==1 (
explorer "%WorkingMountDir%"
goto :USER_EDIT_MODE
)
if %errorlevel%==3 (
goto :SKIP_USER_EDIT
)
echo %Separator%
echo あなたがWindowsPEに行った変更を保存しています。
echo %Separator%
@rem WindowsPE環境の変更を適用する
start /wait /B cmd /c dism /Commit-Wim /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /MountDir:"%WorkingMountDir%"
:SKIP_USER_EDIT
echo.
echo %Separator%
echo WindowsPEイメージをアンマウントとクリーンアップを行います。
echo %Separator%
@rem WindowsPE環境をアンマウント
start /wait /B cmd /c dism /UnMount-Image /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /MountDir:"%WorkingMountDir%" /discard
@rem DISMのクリーンアップ
start /wait /B cmd /c dism /LogLevel:%DismLogLevel% /LogPath:"%DismLogPath%" /Cleanup-Wim
echo.
@rem 作成したWindowsPE環境(amd64)をisoイメージ化する
echo.
echo %Separator%
echo WindowsPEのISOイメージを以下に作成しています
echo %OutputISOImage%
echo %Separator%
echo.
start /wait /B cmd /c Makewinpemedia /iso "%WorkingDir%" "%OutputISOImage%"
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment