cwindows-installerextractcab

How extract deployment files from MSI database


MSI database contains set of tables, and I can successfully enumerate File table, which has all deployable file' meta-deta. What I need to extract is the actual contents of those files. msiexec, lessmsi, 7-zip all can do it, but I couldn't find any source/API to do it.

What I've discovered it that all other (resource) files are in Binary table, and Data field can be used to get content of those files (like icons, custom DLL etc).

Further, I found and know that Media table contains information about the .CAB file (MSI has all content embedded with <MediaTemplate EmbedCab="yes"/>. This simply means the CAB file contains the actual content. I probably need to read contents from "Structured Storage" of the .msi file.

How to extract the contents of CAB/MSI file, using native C Msi* functions?


Solution

  • Phil has given you the easy/simple answer but I thought I might give you a little more information since you've done some research. Checkout:

    https://msdn.microsoft.com/en-us/library/windows/desktop/aa372919(v=vs.85).aspx

    This is where the structured storage is. You'll see something like Disk1.cab as the Name (PK) and binary data. The data is a CAB file with the file entry in the cab matching the File.File column. From there you can use the File.FileName column to get the short name and long name (you'll want the long name no doubt) and do a joint to the Component table to get the directory table ID.

    You'll also need to recurse the directory table to build the tree of directories and know where to put the files.

    Fun stuff. There's some libraries in C# that make this WAY simpler. Or just call msiexec /a as Phil says. :)