Topic: Simple batch files for integrating updates and drivers in Win7
Here's some simple batch files that I've been using to integrate updates and drivers into all indexes of Win7 source files before building .iso.
I thought I'd share them for others.
Make sure to execute these batch files by right-clicking and selecting "Run as administrator".
Set the paths to whatever you like, just be sure to NOT use a trailing backslash in the path (i.e. C:\mnt instead of C:\mnt\ )
To download the patches, I use Windows Updates Downloader with current download lists from this post (not 100% complete, but a great start)
For drivers, I separate my folders into boot & main. Boot drivers are integrated into the boot.wim (index 2) and for me only contain dpms.
Enjoy!
updates-x86.bat
@echo off
::Set Paths
:: Do NOT use trailing backslash in path (i.e. C:\mnt instead of C:\mnt\ )
:Path to mount folder
set mnt=C:\Tools\W7\mount
:Path to source .wim
set src=C:\Tools\W7\Source\x86\sources
:Path to update packages
set updates1=C:\Tools\W7\Updates\Windows_7_SP1_x86_ENU\Critical_Updates
set updates2=C:\Tools\W7\Updates\Windows_7_SP1_x86_ENU\Important_Updates
set updates3=C:\Tools\W7\Updates\Windows_7_SP1_x86_ENU\Optional_Updates
cls
dism /Mount-Wim /WimFile:%src%\install.wim /index:5 /MountDir:%mnt%
dism /Image:%mnt% /Add-Package /PackagePath:%updates1%
dism /Image:%mnt% /Add-Package /PackagePath:%updates2%
dism /Image:%mnt% /Add-Package /PackagePath:%updates3%
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:4 /MountDir:%mnt%
dism /Image:%mnt% /Add-Package /PackagePath:%updates1%
dism /Image:%mnt% /Add-Package /PackagePath:%updates2%
dism /Image:%mnt% /Add-Package /PackagePath:%updates3%
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:3 /MountDir:%mnt%
dism /Image:%mnt% /Add-Package /PackagePath:%updates1%
dism /Image:%mnt% /Add-Package /PackagePath:%updates2%
dism /Image:%mnt% /Add-Package /PackagePath:%updates3%
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:2 /MountDir:%mnt%
dism /Image:%mnt% /Add-Package /PackagePath:%updates1%
dism /Image:%mnt% /Add-Package /PackagePath:%updates2%
dism /Image:%mnt% /Add-Package /PackagePath:%updates3%
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:1 /MountDir:%mnt%
dism /Image:%mnt% /Add-Package /PackagePath:%updates1%
dism /Image:%mnt% /Add-Package /PackagePath:%updates2%
dism /Image:%mnt% /Add-Package /PackagePath:%updates3%
dism /Unmount-Wim /MountDir:%mnt% /commit
echo .........................................
echo Update integration complete
pause
exit
updates-x64.bat
@echo off
::Set Paths
:: Do NOT use trailing backslash in path (i.e. C:\mnt instead of C:\mnt\ )
:Path to mount folder
set mnt=C:\Tools\W7\mount
:Path to source .wim
set src=C:\Tools\W7\Source\x64\sources
:Path to update packages
set updates1=C:\Tools\W7\Updates\Windows_7_SP1_x64_ENU\Critical_Updates
set updates2=C:\Tools\W7\Updates\Windows_7_SP1_x64_ENU\Important_Updates
set updates3=C:\Tools\W7\Updates\Windows_7_SP1_x64_ENU\Optional_Updates
::Do NOT modify anything below this line unless you know what you are doing!
cls
dism /Mount-Wim /WimFile:%src%\install.wim /index:4 /MountDir:%mnt%
dism /Image:%mnt% /Add-Package /PackagePath:%updates1%
dism /Image:%mnt% /Add-Package /PackagePath:%updates2%
dism /Image:%mnt% /Add-Package /PackagePath:%updates3%
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:3 /MountDir:%mnt%
dism /Image:%mnt% /Add-Package /PackagePath:%updates1%
dism /Image:%mnt% /Add-Package /PackagePath:%updates2%
dism /Image:%mnt% /Add-Package /PackagePath:%updates3%
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:2 /MountDir:%mnt%
dism /Image:%mnt% /Add-Package /PackagePath:%updates1%
dism /Image:%mnt% /Add-Package /PackagePath:%updates2%
dism /Image:%mnt% /Add-Package /PackagePath:%updates3%
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:1 /MountDir:%mnt%
dism /Image:%mnt% /Add-Package /PackagePath:%updates1%
dism /Image:%mnt% /Add-Package /PackagePath:%updates2%
dism /Image:%mnt% /Add-Package /PackagePath:%updates3%
dism /Unmount-Wim /MountDir:%mnt% /commit
echo .........................................
echo Update integration complete
pause
exit
drivers-x86.bat
@echo off
::Set Paths
:: Do NOT use trailing backslash in path (i.e. C:\mnt instead of C:\mnt\ )
:Path to mount folder
set mnt=C:\Tools\W7\mount
:Path to source .wim
set src=C:\Tools\W7\Source\x86\sources
:Path to driver packages
set driver-boot=C:\Tools\Drivers\Boot\x86
set driver-main=C:\Tools\Drivers\x86
::Do NOT modify anything below this line unless you know what you are doing!
cls
Dism /Mount-Wim /WimFile:%src%\BOOT.WIM /index:2 /MountDir:%mnt%
Dism /image:%mnt% /Add-Driver /driver:%driver-boot% /recurse
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:5 /MountDir:%mnt%
Dism /image:%mnt% /Add-Driver /driver:%driver-main% /recurse
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:4 /MountDir:%mnt%
Dism /image:%mnt% /Add-Driver /driver:%driver-main% /recurse
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:3 /MountDir:%mnt%
Dism /image:%mnt% /Add-Driver /driver:%driver-main% /recurse
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:2 /MountDir:%mnt%
Dism /image:%mnt% /Add-Driver /driver:%driver-main% /recurse
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:1 /MountDir:%mnt%
Dism /image:%mnt% /Add-Driver /driver:%driver-main% /recurse
dism /Unmount-Wim /MountDir:%mnt% /commit
echo .........................................
echo Driver integration complete
pause
exit
drivers-x64.bat
@echo off
::Set Paths
:: Do NOT use trailing backslash in path (i.e. C:\mnt instead of C:\mnt\ )
:Path to mount folder
set mnt=C:\Tools\W7\mount
:Path to source .wim
set src=C:\Tools\W7\Source\x64\sources
:Path to driver packages
set driver-boot=C:\Tools\Drivers\Boot\x64
set driver-main=C:\Tools\Drivers\x64
::Do NOT modify anything below this line unless you know what you are doing!
cls
Dism /Mount-Wim /WimFile:%src%\BOOT.WIM /index:2 /MountDir:%mnt%
Dism /image:%mnt% /Add-Driver /driver:%driver-boot% /recurse
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:4 /MountDir:%mnt%
Dism /image:%mnt% /Add-Driver /driver:%driver-main% /recurse
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:3 /MountDir:%mnt%
Dism /image:%mnt% /Add-Driver /driver:%driver-main% /recurse
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:2 /MountDir:%mnt%
Dism /image:%mnt% /Add-Driver /driver:%driver-main% /recurse
dism /Unmount-Wim /MountDir:%mnt% /commit
dism /Mount-Wim /WimFile:%src%\install.wim /index:1 /MountDir:%mnt%
Dism /image:%mnt% /Add-Driver /driver:%driver-main% /recurse
dism /Unmount-Wim /MountDir:%mnt% /commit
echo .........................................
echo Driver integration complete
pause
exit
And for post install options, I use the %cdrom%\sources\$oem$\$$\Setup\scripts\setupcomplete.cmd method (thanks to Ricktendo64 for the .net4 ideas), but I'll be transitioning some of the below to a custom WPIW installer session later.
setupcomplete.cmd for Win7
@echo off
for %%i in (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 if exist %%i:\sources\install.wim set CDROM=%%i:
echo Found CD-Rom as drive %CDROM%
::Begin hotfix install
:Malicious software removal tool
echo Installing Malicious Software Removal Tool
IF EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\windows-kb890830-x64-v3.22.exe /Q
IF NOT EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\windows-kb890830-v3.22.exe /Q
:Defender Definitions
echo Installing Windows Defender Definition updates
IF EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\WinDefUpdate\mpas-fe64.exe /Q
IF NOT EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\WinDefUpdate\mpas-fe.exe /Q
:DirectX
echo Updating DirectX
start /wait %CDROM%\updates\directx\DXSETUP /silent
:NET Framework 4
echo Installing .NET 4 Framework
::start /wait Client\netfx_core_x64.msi EXTUI=1
::start /wait Extended\netfx_extended_x64.msi EXTUI=1
start /wait %CDROM%\updates\dotNetFx40_Full_x86_x64.exe /passive /norestart
IF EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2160841-x64.exe /passive /norestart
IF EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2416472-x64.exe /passive /norestart
IF EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2446708-x64.exe /passive /norestart
IF EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2468871-v2-x64.exe /passive /norestart
IF EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2478663-x64.exe /passive /norestart
IF EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2487367-x64.exe /passive /norestart
IF EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2518870-x64.exe /passive /norestart
IF EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2533523-x64.exe /passive /norestart
IF EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2539636-x64.exe /passive /norestart
IF NOT EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2416472-x86.exe /passive /norestart
IF NOT EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2446708-x86.exe /passive /norestart
IF NOT EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2468871-v2-x86.exe /passive /norestart
IF NOT EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2478663-x86.exe /passive /norestart
IF NOT EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2487367-x86.exe /passive /norestart
IF NOT EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2518870-x86.exe /passive /norestart
IF NOT EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2533523-x86.exe /passive /norestart
IF NOT EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\NDP40-KB2539636-x86.exe /passive /norestart
:options
::Requires .NET 4
echo Installing Super Calendar
IF EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\WinCal-Win7-amd64-en-us.exe /S /v/qb
IF NOT EXIST %SystemRoot%\SysWOW64 start /wait %CDROM%\updates\WinCal-Win7-x86-en-us.exe /S /v/qb
echo Installing Pinball
start /wait %CDROM%\updates\WinPinball-en-us.exe /S /v/qb
:WPIW
::Begin WPIW
echo Starting Windows Post-Install Wizard
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main" /V "Disable Script Debugger" /T "REG_SZ" /D "no" /F
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main" /V "DisableScriptDebuggerIE" /T "REG_SZ" /D "no" /F
::Start %CDROM%\WPI\wpi.exe
::all processing finished, delete used files, and EXIT::
:CLEANUP
start /wait %windir%\Microsoft.NET\Framework\v4.0.30319\ngen executequeueditems
IF EXIST %SystemRoot%\SysWOW64 start /wait %windir%\Microsoft.NET\Framework64\v4.0.30319\ngen executequeueditems
IF EXIST %windir%\Setup\scripts RD /S /Q %windir%\Setup\scripts >nul
DEL /F /Q %0% >nul
exit
And for you testing types, here's some experimental code for all NT6 OS (auto adjusts). Code in-work.
@echo off
:: Do NOT use trailing backslash in paths (i.e. C:\mnt instead of C:\mnt\ )
:: Hardcoded paths (C:\etc) are acceptable, but discouraged in favor of flexible relative paths
:: such as (%~dp0\ "the directory containing this script", or %cd% "current directory", or ..\..\ "back two directories")
:: Network shares (\\server\path) are not supported by this script.
::Set Paths to directories here.
:Path to mount folder
set "mnt=%~dp0mount"
:Path to temp folder
set "tmp=%~dp0temp"
:Path to source .wim files
set "src=%~dp0source"
:Path to driver folders (each should contain x86 & x64 folders)
set "driver-boot=%~dp0Drivers\Boot"
set "driver-main=%~dp0Drivers\Install"
::Do NOT modify anything below this line unless you know what you are doing!
:Environment checks
:DISM-check
IF NOT EXIST "%WINDIR%\SYSTEM32\DISM\DISMHOST.EXE" GOTO ERROR1
:WIM-check
IF NOT EXIST "%src%\*.wim" GOTO ERROR2
:Driver-check
IF NOT EXIST "%driver-boot%\*" GOTO ERROR3
:Index-start
set idx=1
:Index stop
set bootx=2
dism /get-wiminfo /wimfile:"%src%\install.wim" > "%tmp%\index.log"
dism /get-wiminfo /wimfile:"%src%\install.wim" /index:1 > "%tmp%\detail.log"
setlocal EnableDelayedExpansion
set "cmd=findstr /R /N "^^" "%tmp%\index.log" | find /C "Index""
for /f %%a in ('!cmd!') do set indexs=%%a
cls
echo %indexs% Install.wim indexes found.
:Arch detection
if exist "%tmp%\detail.log" (
FOR /F "tokens=* skip=2 usebackq" %%a IN (`FIND "Architecture" "%tmp%\detail.log"`) DO (
set str=%%a
for /f "tokens=2 delims=: " %%b in ('echo !str!') do (
set arch=%%b
))
)
echo The install.wim architecture is %arch%
echo Using boot drivers from folder:%driver-boot%\%arch%
echo Using main drivers from folder:%driver-main%\%arch%
:begin-boot
echo Integrating Boot WIM Index: %idx%
Dism /Mount-Wim /WimFile:"%src%\BOOT.WIM" /index:%idx% /MountDir:"%mnt%"
Dism /image:"%mnt%" /Add-Driver /driver:"%driver-boot%\%arch%" /recurse /forceunsigned
Dism /Unmount-Wim /MountDir:"%mnt%" /commit
if "%idx%"=="%bootx%" set idx=1 & goto begin-install
set /a idx+=1
goto begin-boot
:begin-install
echo Integrating Install WIM Index: %idx%
Dism /Mount-Wim /WimFile:"%src%\install.WIM" /index:%idx% /MountDir:"%mnt%"
Dism /image:"%mnt%" /Add-Driver /driver:"%driver-main%\%arch%" /recurse /forceunsigned
dism /Unmount-Wim /MountDir:"%mnt%" /commit
if "%idx%"=="%indexs%" goto END
set /a idx+=1
goto begin-install
:End
echo .........................................
echo Driver integration complete.
:Cleanup
cd %SYSTEMDRIVE%\
IF EXIST "%tmp%\*" DEL /F /S /Q "%tmp%\*" >nul
echo Cleanup complete.
:Exit
pause
exit
:ERROR1
IF EXIST "%WINDIR%\SYSWOW64\DISM\DISMHOST.EXE" GOTO WIM-check
ECHO DISM utility not found. Please install the Microsoft WAIK suite of utilities.
echo Windows® Automated Installation Kit (AIK) downloads
echo WAIK 3.0: http://www.microsoft.com/download/en/details.aspx?id=5753
echo WAIK 3.1 supplement: http://www.microsoft.com/download/en/details.aspx?id=5188
goto Exit
:ERROR2
IF EXIST "%src%\sources\*.wim" set "src=%src%\sources" & GOTO Driver-check
ECHO WIM files not detected. Please check source directory.
goto Exit
:ERROR3
IF EXIST "%driver-main%\*" GOTO Index-start
ECHO Driver files not detected. Please check driver directory.
goto Exit
Not all heroes wear capes, some wear Kevlar!