|How To Extract a Single File From a Large MSI (4 Ways)|
|Written by Darwin Sanoy|
|Thursday, March 18, 2010 6:25pm|
There may be times when you need a file or two out of a Microsoft SDK or other large distribution. It can be a painful process to install an entire SDK or toolkit to obtain a single file, so we’ve documented some better ways.
We use these methods in the lab exercises of our training courses when a few files are needed from large SDKs or toolkits provided by Microsoft.
Getting your hands on a single file from a Microsoft SDK can be a big pain. Microsoft does not provide the files individually for good reason – developer machines could end up with a very odd mix of file versions from different SDK releases – which would lead to a lot of strange problems for all of us who use software (anyone reading this not use software?)
However, when you truly do need a single file, the time consuming, painful process goes something like this:
In the past I have used the approach of installing the SDK, copying the files to an archive location, and uninstalling the SDK so that I will have access to any other loose files I need at a later date. There are several problems with this: a) I forget where I put them!, b) I end up deleting them because it does not seem to make sense to retain 1 GB of disk space in case I might need a 10 KB file sometime in the next 18 months, c) I rebuild my machine before needing the files again, d) By the time I need them again, I need the latest files from the latest SDK.
Here are some examples of the types of files I have had to deep dive for (If you have other examples, I’d love to hear about them via our Contact Us page!):
Windows Installer File Structures
Some archiving utilities do allow you to open .MSI files and attempt to extract files. However, .MSI file present at least two major challenges:
So let’s take a look at three different ways to accomplish getting a file or two out of an MSI. We will use the example of grabbing wimgapi.dll from waikx86.msi. This MSI has the following attributes: *) files name abstraction for dual x86 and x64 support (file names in cabs are not final names), *) multiple cab files, *) cab files stored internally in the MSI.
Web Installers, MSIs or ISOs
The SDK or toolkit will come as either a web installer (.EXE which downloads the individual files during the install phase), a self contained MSI file with internal cabs, or an ISO. For instance, the Windows Installer SDK is provided as a web installer and an ISO, but the Windows Debugging Tools come only as a downloadable MSI. If you decide to download the ISO file, you will need a free ISO mounting utility like Virtual Clone Drive or MagicISO Virtual CD/DVD ROM. Both of free these utilities are made by companies that also sell more capable ISO creation software – so do not let their websites confuse you into thinking you have to buy anything simply to mount an ISO.
lessmsi is a small, standalone utility that displays the files in an MSI and allows you to extract them. It was updated to version 1.0.7 in December of 2009. It resolves our two Windows Installer file structure challenges by using the file names in the File table of the package and then finding the file in the correct cab, extracting it and naming it according to the file table name.
Admin installs are a built-in feature of Windows Installer. Completing an admin install gives access to the software files without making any changes to the computer you use to extract the files. It simply extracts all files from the source formats and organizes them in a folder. A few changes are made to the MSI as well. No changes or installation activities happen on the machine running the admin install command line.
MSI package source files can be in one of three formats (not counting an Admin install itself):
An admin install will take any of these formats and convert them to the admin install format – including using folders that are similar to those of the software when it is installed on a computer.
An admin install is triggered by using the “/a” switch on msiexec like this:
Unless the software package has been specially prepared to use admin installs to customize the package, the only prompt will be for the disk location to install the software. Despite the reference to “Network Location” on this dialog, the location can be on a local disk.
This registry file will add an “Extract Admin Install” context menu item to “.MSI” files:
Windows Registry Editor Version 5.00
7zip is an archiving utility that has been given a rudimentary ability to work with MSI files. It will open them and display their file content, including cab files. Clicking a cab file will drill down into that archive similar to have archivers work with compressed archive files. However, since it does not use the files table, you are on your own to translate the filenames in the cabs into the file name you are looking for – this is usually not a difficult process. If there are multiple cab files in the MSI, you have to slog through each one. In the case of WAIK there are five internal cab files. When using lessmsi, I do not see any cab files because it uses the MSI table instead.
PowerArchiver MSI Plug-in
PowerAchiver has a plug-in that extends that product to handle MSI files. Unlike 7zip and lessmsi, it DOES handle external CAB files! When using it It’s primary drawback is that it displays and extracts files according to their abstracted name (MSI File table’s “File” column rather than the “FileName” column.) This callenge is seen in the Windows SDK where many of these abstracted file names are very long. Another challenge is that it displays the .CAB files along side of the file list. The file list is of course what is in the CABs themselves. This wouldn’t be so bad if I wasn’t preprogrammed by standard compressed archive metaphors to start rummaging the sub-cabs directly. However, doing so causes the very slow extraction of that CAB and then it is displayed as a separate archive. If that CAb does not contain what you want, you must reopen the .MSI. If you decide to use this plug-in, you’ll have to teach yourself to ignore the cabs and find the file you are looking for directly in the file list – extracting it will automatically pull it out of the correct cab in the MSI. If there is only one cab, this effect is not as evident. The fact that many .MSIs only contain a single cab is probably the reason that this design issue was not picked up earlier.