Share via


Return of the Little Shop of Drivers

It's been a while since I've posted.  Just over a year actually...  I have this long list of half started posts, but just somehow can never seem to find the time to finish them up.  However, with the exciting new release of Win7, I have managed to update my scripts to automatically add stuff to the WIMs for deployment.  As such, here is the updated script deprecating IMAGEX and PEIMG for DISM.  Hope this helps with some of your automation needs.

Editorial comments:  I do like DISM much better as it is a little easier in the syntax, plus searches directory heirarchies for drivers.  This makes it a little easier when I toss stuff into %DRIVERS_ROOT_PATH% so I don't have to waste time figuring out which directory contains the actual drivers (as you may have noticed, there is sometimes a whole bunch of other stuff in driver downloads).

 @echo off
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Check Inputs
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
IF "%1"=="" (
Echo Enter the directory root for the drivers and packages to add to the image.
GOTO END
)

IF "%2"=="" (
Echo Enter WIM file name.  This must be in the root of the
GOTO END
)

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::SET Variables
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SET REFERENCENAME=%1
SET MOUNTPOINT=D:\FOO\%REFERENCENAME%
SET FILES_ROOT_PATH=D:\%REFERENCENAME%
SET IMAGEFILE=%FILES_ROOT_PATH%\%2
SET DRIVERS_ROOT_PATH=%FILES_ROOT_PATH%\Drivers
SET PACKAGES_ROOT_PATH=%FILES_ROOT_PATH%\Packages
SET LOGS_ROOT_PATH=%FILES_ROOT_PATH%\Logs
::SET WIN_AIK_INSTALL_PATH=C:\Program Files\Windows AIK\Tools
::echo %WIN_AIK_INSTALL_PATH%

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Ensure needed directories exist and are ready to be used
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if not exist %MOUNTPOINT% (md %MOUNTPOINT%) ELSE (DISM /Unmount-Wim /MountDir:%MOUNTPOINT% /discard)
if not exist %LOGS_ROOT_PATH% (md %LOGS_ROOT_PATH%) ELSE (del /s /q %LOGS_ROOT_PATH%>NUL)

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Identify number of images in WIM and process each image
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
for /f "tokens=1,2 delims=: " %%i in ('dism /get-wiminfo /wimfile:%IMAGEFILE%') do if "%%i"=="Index" SET IMAGE_COUNT=%%j
Echo This WIM contains %IMAGE_COUNT% image(s).
For /l %%i in (1,1,%IMAGE_COUNT%) do call :update %IMAGEFILE% %%i
GOTO END

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Process per image steps
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:update
Echo Updating %1 - Image #%2
DISM /Mount-WIM /WimFile:%1 /Index:%2 /MountDir:%MOUNTPOINT%
DISM /Image:%MOUNTPOINT% /Add-Driver /Driver:%DRIVERS_ROOT_PATH% /recurse /ForceUnsigned
::for /f %%i in ('dir /ad /b %PACKAGES_ROOT_PATH%') do Call :InstallPackage %%i %2
DISM /Unmount-Wim /MountDir:%MOUNTPOINT% /Commit
goto :EOF

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Install a specified package
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:InstallPackage
Echo Installing Package %PACKAGES_ROOT_PATH%\%1
ECHO DISM /Image:%MOUNTPOINT% /Apply-Unattend:%PACKAGES_ROOT_PATH%\%1\%1.xml /Log-Path:%LOGS_ROOT_PATH%\%2-%1>NUL
IF ERRORLEVEL 1 ECho       ERROR:  Couldn't Install Package "%1"
GOTO :EOF

:END
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Clean up variables
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SET IMAGE_COUNT=
SET REFERENCENAME=
SET IMAGEFILE=
SET MOUNTPOINT=
SET FILES_ROOT_PATH=
SET DRIVERS_ROOT_PATH=
SET PACKAGES_ROOT_PATH=
SET WIN_AIK_INSTALL_PATH=