Welcome to MSDN Blogs Sign in | Join | Help

What's in a Patch

Windows Installer relies on structured storage for information about the installation package and to store data used by the installation such as any Binary types and cabinet files. Patches (.msp files) are no different in structure but will contain different data.

Up until Windows Installer 3.0, patches themselves didn't contain any standard tables but could contain user tables. For Windows Installer 3.0 the tables MsiPatchSequence and MsiPatchMetadata could be added as meaningful tables. What patches have always contained, though, was a set of sub-storages for each transform that transforms the target installer package (.msi file) to the upgraded installer package, and possibly a stream for a single cabinet file that contained the patched files, either in whole or in part as delta patches. Like all Windows Installer files, patches also contain a summary information stream, but some properties mean different things like the Revision Number summary property which contains only the patch code prior to Windows Installer 2.0, and contains the patch code followed by a list of patch codes to obsolete.

The transforms embedded in patches contain all the differences between a certain target and upgrade package. If you're using PatchWiz.dll, a transform is created for each corresponding row in the TargetImages and UpgradeImages tables. If you use a SQL expression to select from the temporary _Storages table you can enumerate all sub-storages within the package, which will list two transforms for each corresponding target and upgrade package. One transform is the actual difference between the target and upgrade packages, while the other transform beginning with '#' adds entries to the Patch, PatchPackage, Media, InstallExecuteSequence, and the AdminExecuteSequence tables. This transform is not applied to administrative installation images because the patch is merged directly into the installer package so no patch-specific data is required.

Below you can see a basic representation of an MSP file, though an MSI, MSM (merge module), or PCP (patch creation properties) file has the same structure though they don't typically contain transforms but can.

MSP File Structure
Published Thursday, September 01, 2005 6:55 PM by Heath Stewart
Filed under: ,

Comments

Thursday, September 01, 2005 10:12 PM by Nick Parker

# re: What's in a Patch

Interesting, what client can you use to run a SQL expression against it?
Thursday, September 01, 2005 10:26 PM by Heath Stewart

# re: What's in a Patch

The SQL - rather, SQL-like expressions - can be executed using the Windows Installer functions and automation interfaces, like Database.OpenView documented at http://msdn.microsoft.com/library/en-us/msi/setup/database_openview.asp.

Many of the script under Samples\SysMgmt\Msi\Scripts in your Platform SDK installation directory like WiStream.vbs and WiSubStg.vbs will enumerate the _Streams and _Storages tables, respectively. They don't currently work for patches though, and I'll blog why later.
Friday, September 02, 2005 7:41 PM by Heath Stewart's Blog

# Updated Sample MSI Scripts

Changes the sample MSI scripts WiStream.vbs and WiSubStg.vbs to support patch files (.msp files).
Monday, September 12, 2005 12:36 PM by Heath Stewart's Blog

# How Patching Works

What patches do when being installed or uninstalled.
Tuesday, February 14, 2006 7:47 PM by Heath Stewart's Blog

# Extract Files from Patches

How to extract files from a patch by patching an administrative installation and the hard way using OLE structured storage APIs.
Tuesday, February 21, 2006 2:04 PM by Heath Stewart's Blog

# Determine Which Files are Being Patched

How to determine which files are being patched with a custom action.
Monday, February 27, 2006 11:58 AM by Heath Stewart's Blog

# Identifying Windows Installer File Types

How to identify different Windows Installer file types without relying on the file extension.
Friday, April 07, 2006 5:43 PM by Heath Stewart's Blog

# Patch Files Extractor

Download the source and a release binary for a tool to extract transforms and binary streams like cabinets from Windows Installer files, such as patches.
Friday, May 19, 2006 4:48 PM by Heath Stewart's Blog

# File Sequencing and How Files are Located

How file sequences identify the file source for installation, and how patches resolve source for new files.
Wednesday, June 14, 2006 5:32 PM by Heath Stewart's Blog

# Cumulative Service Packs with MinorUpdateTargetRTM

How to create cumulative service packs easily to apply with Windows Installer 3.1 and newer.
Tuesday, July 18, 2006 2:45 AM by Gaurav

# re: What's in a Patch

I want to extract a table from the MSP file and save it to a database, is this possible using C#
Tuesday, July 18, 2006 4:33 PM by Heath Stewart

# re: What's in a Patch

Gaurav, except the only two common tables - and currently the only two tables that mean anything to Windows Installer - are the MsiPatchMetadata and MsiPatchSequence tables. If you want to get the transforms to a table that the transforms within the patch make, you need to extract the right transform (search my blog for "extractor") and apply that to an open database handle to the target MSI.

Can C# do this? Of course, but you'll need to P/Invoke the MSI APIs.
Wednesday, July 19, 2006 3:00 AM by Gaurav

# re: What's in a Patch

Thanks Heath,
Let me put my issue more explicitly. I have an application wherein the user would upload his msi file along with some xml files (these would just contain some information regarding the dependencies etc). Now i have to extract these xml's from the msi and save it to the database, all using C#.

I am not sure how to approach this problem. Please enlighten.
I would appreciate if you can give me an exhaustive picture (i am new to msi's and C#).

THANKS IN ADVANCE.
Gaurav
Wednesday, July 19, 2006 12:57 PM by Heath Stewart

# re: What's in a Patch

Gaurav, comments in a blog are hardly the way to go into detail. I do wonder why you're using MSIs in this way. Are they used to install anything, or just as packaging? If you just need packaging, then use a ZIP file or some other archive format. .NET 2.0 even has supported for ZIP (well, LZ compressed streams - not ZIP file systems but that's not hard to build from what's provided).

If you just want to get the files out, again, see my patch file extractor at http://blogs.msdn.com/heaths/archive/2006/04/07/571138.aspx. You could do much the same thing in C#, but you will have to P/Invoke the MSI APIs like MsiOpenDatabase, MsiDatabaseOpenView, MsiViewExecute, MsiViewFetch, and MsiRecordReadStream. In my msix.exe tool sample, look how I extract the CABs.

Once you get the CAB, you'll need something to expand them and I'm not aware of any libraries that do this currently, but you can use Process.Start to shell-out to some Platform SDK tool like cabarc.exe.

If you're going to shell out, though, just use Process.Start to call the following individually:

msiexec.exe /a <MSI file path> TARGETDIR="<target DIR>"

msiexec.exe /a "<target DIR>\<MSI file name>" /p "<patch path>"

Then you can get the files out of your patch.
Monday, August 14, 2006 2:26 PM by Heath Stewart's Blog

# Been Busy on Visual Studio 2005 Service Pack 1

I've been away for a while, though I've barely left the Microsoft campus. As we prepare for Visual Studio...
Tuesday, August 22, 2006 12:47 PM by Christopher Painter

# P/Invoke

Heath-

I've been converting some VBScript files to C# going from the session object to P/Invoke.

I have a script that walks an ArrayList and perfoms and update apx 1500 times on an MSI table using a function similar to WiRunSQL.  What took seconds now takes 6 minutes.  I split the function into 3 functions;

init ( MsiOpenDatabase )
exec ( create view, execute view, commit, closehandle view )
final ( close database handle

And now it takes 3 minutes to run.  Is P/Invoke really that slow or am I doing something wrong?  The only thing I can think to do next is pass the arraylist to a COM via interop and perform the updates there outside of the CLR.
Tuesday, August 22, 2006 12:47 PM by Christopher Painter

# re: What's in a Patch

The real cost seeme to be associated with the MsiDatabaseCommit call.  Moving this to the finalization method really sped things up.
Wednesday, August 23, 2006 7:22 PM by Heath Stewart's Blog

# Size does Matter

In response to a previous post where I mentioned that work was being done on Visual Studio 2005 SP1,...
Wednesday, October 04, 2006 9:09 PM by Heath Stewart's Blog

# Size does Matter

In response to a previous post where I mentioned that work was being done on Visual Studio 2005 SP1,
Wednesday, October 04, 2006 9:09 PM by Heath Stewart's Blog

# Been Busy on Visual Studio 2005 Service Pack 1

I've been away for a while, though I've barely left the Microsoft campus. As we prepare for Visual Studio
Tuesday, November 07, 2006 7:11 PM by Heath Stewart's Blog

# Viewing Patches in Orca

I am often asked why file changes don't appear in the handy Windows Installer tool, Orca. When people

Friday, December 29, 2006 5:23 AM by Heath Stewart's Blog

# The Visual Studio 2005 Service Pack 1 Installation Experience

Visual Studio 2005 Service Pack 1 can take a long time to install and may apply to multiple products

Saturday, September 01, 2007 1:19 PM by Heath Stewart's Blog

# Column Types Cannot be Changed in a Patch or Transform

Transforms can change just about anything in an installation package - even the code page. Transforms

Sunday, September 02, 2007 2:43 AM by Noticias externas

# Column Types Cannot be Changed in a Patch or Transform

Transforms can change just about anything in an installation package - even the code page. Transforms

New Comments to this post are disabled
 
Page view tracker