There are 4 prerequisite applications that will help out, the 4th one is not necessarily required. For MSI repackaging or extracting msi files you will still need to read the entire article, but you won’t need to add the new rows in the tables. You will just need to look at the files that you need to change in the File table under the File Name column or the source_path column (done with orca or Instedit). And then you’d have to modify the size and versions.
1. The first application that is required is Orca.exe this application only helps with editing of the Database inside the MSI file. There are replacement apps for ORCA like: SuperOrca, CamWood app Editor184.108.40.206 (at this time) and InstEdit. I prefer InstEdit (http://www.instedit.com) because you can right click on the MSI file and have InstEd as the option to edit the MSI file.
2. The second app is MSIdb.exe. We use this tool to separate the database part of the MSI file from the archive part which is a .cab archive. MSIdb.exe is a little graphic utility that can extract the .CAB file from an MSI file and add it back into an MSI file modified. It comes with Microsoft Windows Installer SDK 4.5 .To get your hands on this little tool either install Microsoft Installer 4.5 and then go to C:\Program Files\Windows Installer 4.5 SDK\TOOLS and copy it where you need it. To extract the *.cab archive from the msi file we need to work in command line (CMD.exe). The command to separate the .CAB looks something like this:
msidb.exe -d application.msi –k file.cab
and to reinsert the cab the command is like this:
msidb.exe -d application.msi –a file.cab
the difference is in the switches (-k and –a). To extract the cab file from the MSI use:
msidb -d “target.msi” -x “Data1.cab” or the application in step 4.
If unsure about the name of the cabinet file in the MSI file then open the MSI file with ORCA or similar App and check for the name in the Media table under “Cabinet” column. Mine had the “#” sign before the name but when I extract it from the MSI the name did not Include the “#” sign, therefore if stuck on this step just try the name without the # character (if still in doubt just look at app 4).
3. The third application is Iexpress.exe that comes with Windows XP. This app can be run from the run command dialog in start menu. Now the tricky part is that when iexpress.exe is run to recreate a cab file. The names of the files have to be added into archive in the same sequence as they are in the component table in the MSI database table. It took me some time to figure it out because I was getting errors with files missing.
4. The 4th app is called MSI Unpacker, I think and can be found at http://www.jsware.net/jsware/msicode.php5 this one helps you extract the cab file without knowing its name, and it add the cab extension to it automatically. Moreover the app can do more but it doesn’t help with our case.
Altering the database for file addition.
The steps of this maneuver can be skipped and altered depending on the situation therefore I will start with the editing of the database with Instedit. These DB editing steps should be in order but they can be skipped and altered too:
We will open the .MSI file with InstEdit and on the tables menu we go to Components table. There we add a new row in case we want to add a file to our installation. A new dialog box will pop up and we will need to fill in the forms there.
This Hexadecimal number is obtained by clicking the star and I think it just kind of hashes the name “testfile” into this long string. The value TARGETDIR is from a different table but it represents the location of the application in program files. If you desire a different location you need to look into the directory table and figure it out how is interpreted there. But I think windows installer understands for example “AppDataFolder” as C:\Program Files. Therefore you can add different folders where you want the files to be installed. The KeyPath string (72) represents the actual name of the file in the archive, I suggest you keep it without an extension. Then go to FeatureComponents table and add another row at the bottom of the list.
On the File table we need to add another entry row and the values look like this:
The sequence number in the last line has to incremented from the preceding file. The names of the file have to be consistent with the actual file inside the archive. In this example the file name in the first line is the actual name of the file inside the archive. The second row refers to a different name from the different table but I chose it to be the same and it works, do the same if in doubt. The size has to be the size of the file in bytes. I also think that is not relevant but in any case make sure you choose the Size, in bytes, NOT the size on the disk. This way worked for me.
Now we have to go to the Media table and alter the LastSequence number and incremented by the same number of files we are adding to the MSI file. Notice that last sequence number 23 is the same as the number in the sequence two images up.
Compressing the files into a new CAB file.
After that we should be ready to compress the cab file with all the additions and insert it into the MSI file.
Working With the CAB file
To do that we need to extract the CAB archive described in step 2. Then extract the files into a folder, then add the new files and compress it back to a cab with the same name. MAKE SURE THAT THE FILES ADDED INTO ARCHIVE ARE IN THE SAME ORDER AS IN THE Sequence order in the File table in the MSI database. If you get an error try adding the files one by one into archive.
Adding the files into a CABINET Archive:
Now Click the add files button and make sure you add all the files in order to archive. I am emphasizing this because usually they are added by name in order into the archive but for some reason windows cannot arrange the in order of the name correctly. Therefore I had to do it the hard way. I created a notepad file with all the names in the order they were in the order that they were in the Sequence in the File table. Then I copied and pasted the names 5 by five into the Add files Dialog box.
The SED file is like a batch file that can be reopened and added to incase of new modifications. This will save time with the file sequence adding.
Then click finish and browse to find the newly created Cabinet archive in the root of the user profile, unless you selected another location in Package Name and Options screen.
Give me your feedback. I know there might be other methods but I am just tired of incomplete methods. I just needed to write one complete method of adding files and or replacing them. Moreover this was done on a small application that was only one MSI file. Perhaps larger apps work differently.
There is a small addition to this post about setup files.
Some comments might help future posts, as well as this one!