What's in a Patch

What's in a Patch

  • Comments 30

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
Leave a Comment
  • Please add 1 and 4 and type the answer here:
  • Post
  • Interesting, what client can you use to run a SQL expression against it?
  • 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.
  • Changes the sample MSI scripts WiStream.vbs and WiSubStg.vbs to support patch files (.msp files).
  • What patches do when being installed or uninstalled.
  • How to extract files from a patch by patching an administrative installation and the hard way using OLE structured storage APIs.
  • How to determine which files are being patched with a custom action.
  • How to identify different Windows Installer file types without relying on the file extension.
  • 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.
  • How file sequences identify the file source for installation, and how patches resolve source for new files.
  • How to create cumulative service packs easily to apply with Windows Installer 3.1 and newer.
  • I want to extract a table from the MSP file and save it to a database, is this possible using C#
  • 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.
  • 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
  • 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.
  • I've been away for a while, though I've barely left the Microsoft campus. As we prepare for Visual Studio...
Page 1 of 2 (30 items) 12