@echo off
:: Install the "Windows Assessment and Deployment Kit (Windows ADK)"
:: You will only need to install the "Deployment Tools" and "Windows Preinstallation Environment (Windows PE)"
::
:: Create the following folders:
:: C:\my_Distribution
:: C:\my_Distribution\dvd
:: C:\my_Distribution\updates (if you want to integrate updates)
::
:: If you want the Windows 8.1 setup does not ask for product key at the beginning of the setup.
:: - Copy EI.cfg to "C:\my_Distribution"
:: OR
:: If you want to use PID.txt file to automate product key entry.
:: - Copy PID.txt to "C:\my_Distribution"
:: - Note that in this script, the PID.txt will be copied only if you make the Core or Pro version.
::
:: If you want to use SetupComplete.cmd file, copy SetupComplete.cmd to "C:\my_Distribution"
::
:: Copy the files from the Windows 8.1 (x86 or x64) installation media to "C:\my_Distribution\dvd"
::
:: If you want to integrate updates, copy (x86 or x64) update files (*.msu, *.cab) to "C:\my_Distribution\updates"
::
:: Save this file as "Integration.cmd" and copy file to "C:\my_Distribution"
::
:: Run as administrator "Deployment and Imaging Tools Environment"
:: Run the command: C:\my_Distribution\Integration.cmd
:: ----------------------------------------------------------------------------
setlocal EnableExtensions
setlocal EnableDelayedExpansion
set OS=Windows_8.1
:: You can change these variables if you use different file path
set BaseDir=C:\my_Distribution
set WimSource=%BaseDir%\dvd\sources
set updates=%BaseDir%\updates
:: ----------------------------------------------------------------------------
if not exist "%KitsRoot%" (
echo Error: This script can only be run from an elevated ADK prompt.
echo Press any key to exit...
pause >nul
exit
)
if not exist "%WimSource%\install.wim" (
echo Error: Missing source files.
echo Press any key to exit...
pause >nul
exit
)
:: ----------------------------------------------------------------------------
:: Setting source WIM image mount folder path variables
if exist "%BaseDir%\mount" rd /s /q "%BaseDir%\mount"
set InstallMount=%BaseDir%\mount\install
md "%InstallMount%"
set BootMount=%BaseDir%\mount\boot
md "%BootMount%"
set WinReMount=%BaseDir%\mount\winre
md "%WinReMount%"
:: ----------------------------------------------------------------------------
echo.
echo Give in the version you want to make: [1] = Pro, [2] = Core, [3] = Pro+Core
choice /c 123 /n /m ":"
if errorlevel 3 goto PRO_and_CORE
if errorlevel 2 goto CORE
if errorlevel 1 goto PRO
:PRO
set Index=1
set Edition=Pro
goto END
:CORE
set Index=2
set Edition=Core
goto END
:PRO_and_CORE
set Index=1
set Edition=PRO_and_CORE
goto END
:END
:: ----------------------------------------------------------------------------
echo.
echo Do you want to add NET Framework 3.5? [Y] [N]
choice /c YN /n /m ":"
if errorlevel 2 goto END
if errorlevel 1 goto NET35
:NET35
set Add_NET35=yes
goto END
:END
:: ----------------------------------------------------------------------------
echo.
echo Do you want to remove Modern apps from the Windows 8.1 ? [Y] [N]
choice /c YN /n /m ":"
if errorlevel 2 goto END
if errorlevel 1 goto MODERN_APPS
:MODERN_APPS
set RemoveModernApps=yes
goto END
:END
:: ----------------------------------------------------------------------------
call :Copy_EI.cfg
call :Copy_PID.txt
call :Copy_SetupComplete.cmd
:: ----------------------------------------------------------------------------
call :INTEGRATION
if "%Edition%"=="PRO_and_CORE" (goto PRO_and_CORE) else (goto END)
:PRO_and_CORE
if "%Index%"=="1" (set Index=2) else (goto END)
call :INTEGRATION
:END
:: ----------------------------------------------------------------------------
call :BUILD_ISO_IMAGE
call :CLEANING_UP
echo.
echo Press any key to exit...
pause >nul
exit
:: ----------------------------------------------------------------------------
:: Copy EI.cfg
:: ----------------------------------------------------------------------------
:Copy_EI.cfg
if exist "%BaseDir%\EI.cfg" (
xcopy /q /y "%BaseDir%\EI.cfg" "%WimSource%" >nul
echo.
echo The EI.cfg file has been copied to the "%WimSource%" folder.
)
goto :eof
:: ----------------------------------------------------------------------------
:: Copy PID.txt
:: ----------------------------------------------------------------------------
:Copy_PID.txt
if exist "%BaseDir%\EI.cfg" goto :eof
if exist "%BaseDir%\PID.txt" (goto PID_TXT) else (goto :eof)
:PID_TXT
if "%Edition%"=="PRO_and_CORE" (goto :eof
) else (
xcopy /q /y "%BaseDir%\PID.txt" "%WimSource%" >nul
echo.
echo The PID.txt file has been copied to the "%WimSource%" folder.
)
goto :eof
:: ----------------------------------------------------------------------------
:: Copy SetupComplete.cmd
:: ----------------------------------------------------------------------------
:Copy_SetupComplete.cmd
if exist "%BaseDir%\SetupComplete.cmd" (
if not exist "%WimSource%\$OEM$\$$\Setup\Scripts" md "%WimSource%\$OEM$\$$\Setup\Scripts"
xcopy /q /y "%BaseDir%\SetupComplete.cmd" "%WimSource%\$OEM$\$$\Setup\Scripts" >nul
echo.
echo The SetupComplete.cmd file has been copied to the "%WimSource%\$OEM$\$$\Setup\Scripts" folder.
)
goto :eof
:: ============================================================================
:: Start integration
:: ============================================================================
:INTEGRATION
echo.
echo Integrating install WIM image index:%Index%
:: ----------------------------------------------------------------------------
:: Mount install.wim
:: ----------------------------------------------------------------------------
dism /Mount-Image /ImageFile:"%WimSource%\install.wim" /Index:%Index% /MountDir:"%InstallMount%"
:: ----------------------------------------------------------------------------
:: Architecture variables
:: ----------------------------------------------------------------------------
if exist "%InstallMount%\Windows\SysWOW64" set Arch=x64
if not exist "%InstallMount%\Windows\SysWOW64" set Arch=x86
:: ----------------------------------------------------------------------------
:: NET Framework 3.5
:: ----------------------------------------------------------------------------
if "%Add_NET35%"=="yes" (goto ADD_NET35) else (goto END)
:ADD_NET35
dism /Image:"%InstallMount%" /Enable-Feature /FeatureName:NetFX3 /All /LimitAccess /Source:"%WimSource%\sxs"
goto END
:END
:: ----------------------------------------------------------------------------
:: Integrate updates
:: ----------------------------------------------------------------------------
if exist "%updates%\*.cab" goto ADD_PACKAGE
if exist "%updates%\*.msu" goto ADD_PACKAGE
goto END
:ADD_PACKAGE
if exist "%updates%\*.msu" expand "%updates%\*.msu" -F:Win*.cab "%updates%"\ >nul
if exist "%updates%\*.msu" del /f /q "%updates%\*.msu" >nul
dism /Add-Package /Image:"%InstallMount%" /PackagePath:"%updates%"
goto END
:END
:: ----------------------------------------------------------------------------
:: Remove Modern apps
:: ----------------------------------------------------------------------------
:: How to get a list of modern apps?
:: dism /Image:"%InstallMount%" /Get-ProvisionedAppxPackages | clip
:: NOTE: This script is only for Windows 8.1 with Update 12/15/2014 (includes November 2014 update roll up)
if "%RemoveModernApps%"=="yes" (goto REMOVE_MODERN_APPS) else (goto END)
:REMOVE_MODERN_APPS
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.BingFinance_2014.926.253.3184_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.BingFoodAndDrink_2014.926.254.3803_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.BingHealthAndFitness_2014.926.255.3988_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.BingMaps_2014.830.1811.3840_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.BingNews_2014.926.2134.2947_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.BingSports_2014.926.258.4003_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.BingTravel_2014.926.259.4931_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.BingWeather_2014.928.34.2811_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.HelpAndTips_2014.716.611.79_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.Office.OneNote_2014.921.1853.4418_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.Reader_2014.312.322.1510_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.SkypeApp_2014.731.933.5139_neutral_~_kzf8qxf38zg5c
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.WindowsAlarms_2013.1204.852.3011_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.WindowsCalculator_2013.1007.1950.2960_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:microsoft.windowscommunicationsapps_2014.830.2330.2719_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.WindowsReadingList_2014.626.1418.1617_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.WindowsScan_2013.1007.2015.3834_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.WindowsSoundRecorder_2013.1010.500.2928_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.XboxLIVEGames_2013.1011.10.5965_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.ZuneMusic_2014.929.2145.59_neutral_~_8wekyb3d8bbwe
dism /Image:"%InstallMount%" /Remove-ProvisionedAppxPackage /PackageName:Microsoft.ZuneVideo_2014.1002.954.4888_neutral_~_8wekyb3d8bbwe
goto END
:END
:: ----------------------------------------------------------------------------
:: Unmount install.wim
:: ----------------------------------------------------------------------------
dism /Unmount-Image /MountDir:"%InstallMount%" /commit
:: ----------------------------------------------------------------------------
:: Rebuild install.wim
:: ----------------------------------------------------------------------------
dism /Export-Image /SourceImageFile:"%WimSource%\install.wim" /SourceIndex:%Index% /DestinationImageFile:"%WimSource%\install_new.wim" /CheckIntegrity /Compress:max
if "%Edition%"=="PRO_and_CORE" (goto PRO_and_CORE) else (goto FINISHING)
:PRO_and_CORE
if "%Index%"=="1" (goto :eof) else (goto FINISHING)
:FINISHING
del /f /q "%WimSource%\install.wim" >nul
ren "%WimSource%\install_new.wim" "install.wim"
goto :eof
:: ============================================================================
:: Integration complete
:: ============================================================================
:: ----------------------------------------------------------------------------
:: Build ISO image
:: ----------------------------------------------------------------------------
:BUILD_ISO_IMAGE
echo.
echo Building ISO image file for BIOS and UEFI boot mode.
echo.
echo As long as the largest file is under ~4GB, it will fit on a UEFI boot mode compatible FAT32 USB flash drive.
if "%Edition%"=="PRO_and_CORE" (goto PRO_and_CORE) else (goto PRO_or_CORE)
:PRO_and_CORE
set iso_volume_label=%OS%_%Arch%
set iso_file_name=%OS%_%Arch%.iso
goto END
:PRO_or_CORE
set iso_volume_label=%OS%_%Edition%_%Arch%
set iso_file_name=%OS%_%Edition%_%Arch%.iso
goto END
:END
set iso_path=%BaseDir%\iso
if not exist "%iso_path%" md "%iso_path%"
if exist "%iso_path%\%iso_file_name%" del /f /q "%iso_path%\%iso_file_name%" >nul
oscdimg -o -u2 -udfver102 -bootdata:2#p0,e,b"%BaseDir%\dvd\boot\etfsboot.com"#pEF,e,b"%BaseDir%\dvd\efi\microsoft\boot\efisys.bin" -l%iso_volume_label% "%BaseDir%\dvd" "%iso_path%\%iso_file_name%"
goto :eof
:: ----------------------------------------------------------------------------
:: Cleaning up
:: ----------------------------------------------------------------------------
:CLEANING_UP
rd /s /q "%BaseDir%\dvd"
md "%BaseDir%\dvd"
rd /s /q "%BaseDir%\mount"
explorer "%iso_path%"
goto :eof
:: ----------------------------------------------------------------------------