Offline WIM patching with DISM: a more automated method

This is a request that I get fairly often, and one that I’ve been working on for a while.  If you have an existing WIM and just need to update it with the latest patches that you have already deployed, it can be done quickly and easily with DISM.  I have seen several posts about injecting a single patch or downloading and copying patches to a single location, but if you already have them sitting on your ConfigMgr 2007 server, there’s no need to make extra copies.

 

First of all, you need to set up the folder structure.  I use a base folder named WIMs.  Within that folder, I have one batch file and one subfolder for each operating system type, with a common naming convention.  For this example I’ll use 7x64SP1.

image

 

Drop the WIM file in the subfolder with the same name.

image

 

Edit the 3 variables in the Batch file attached at the end of this post:

REM =================
REM EDIT THIS SECTION
REM =================

REM IMAGETYPE IS THE SUBFOLDER AND WIM FILE NAME
SET IMAGETYPE=7X64SP1

REM SEARCH DEFINES WHAT UPDATE FILES YOU WANT TO APPLY
SET SEARCH=Windows6.1*-x64.cab

REM XDRIVE MAPS YOUR PATCH SOURCE FOLDER
SET XDRIVE=labsccm01d$pkgsrcwsus

 

Open a command prompt *as administrator* and brows to the WIMs folder, then call off the batch file.

image

 

It will make a copy of your source wim including the current date in the name, mount it, patch it, and unmount it when it’s finished.  Note that it will temporarily map an X drive to where your patches reside.  The entire process can take a long time there are a lot of applicable patches, but once you launch the batch file the rest happens on its own.  Go get some coffee, and come back in a while to see it complete.

 

Here is the batch file: Build 7X64SP1

It doesn’t appear to want to post as a file, so if you like to copy and paste…

@ECHO OFF

CLS
REM =================
REM EDIT THIS SECTION
REM =================

REM IMAGETYPE IS THE SUBFOLDER AND WIM FILE NAME
SET IMAGETYPE=7X64SP1

REM SEARCH DEFINES WHAT UPDATE FILES YOU WANT TO APPLY
SET SEARCH=Windows6.1*-x64.cab

REM XDRIVE MAPS YOUR PATCH SOURCE FOLDER
SET XDRIVE=labsccm04d$pkgsrcwsus

REM ====================
REM NOTHING MORE TO EDIT
REM ====================

CLS

ECHO Connecting to patch share (X:)…
REM DISCONNECT NETWORK DRIVE IF IN USE
NET USE X: /D /Y > NUL 2>&1
REM MAP NEW DRIVE
NET USE X: %XDRIVE% /PERSISTENT:NO > NUL 2>&1

SET IMAGEFILE=%IMAGETYPE%%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%.WIM

ECHO Copying %IMAGETYPE%.WIM to %IMAGEFILE%…
COPY /Y %IMAGETYPE%%IMAGETYPE%.WIM %IMAGEFILE%
ECHO Mounting %IMAGEFILE%…
REM UNMOUNT AND DELETE ANY UNFINISHED WORK
DISM /UNMOUNT-WIM /MOUNTDIR:SERVICING /DISCARD > NUL 2>&1
RMDIR /S /Q SERVICING > NUL 2>&1
REM MOUNT NEW WIM FOR SERVICING
MKDIR SERVICING
DISM /MOUNT-WIM /WIMFILE:%IMAGEFILE% /INDEX:1 /MOUNTDIR:SERVICING

ECHO Applying patches to %IMAGEFILE%…
FOR /R X: %%G IN (%SEARCH%) DO (DISM.EXE /IMAGE:SERVICING /ADD-PACKAGE /PACKAGEPATH:%%G)

ECHO Saving changes to %IMAGEFILE%…
DISM /UNMOUNT-WIM /MOUNTDIR:SERVICING /COMMIT
RMDIR /S /Q SERVICING > NUL 2>&1

SET IMAGETYPE=
SET IMAGEFILE=
SET SEARCH=
SET XDRIVE=
NET USE X: /D /Y > NUL 2>&1

PAUSE

 

 

email

Written by , Posted .