Sometimes when you need to deploy an application, you may need to add additional files to get installed onto the target machine, they could be configuration or license files etc… The first thing you need to do is create a CAB file with the additional files you want to install / deploy with the MSI. A CAB file is a Microsoft compressed archive from before Zip files were widely adopted. Every version of Windows since 2000, has shipped with a tool built in to create CAB files called “makecab”.
Make CAB file with desired additional files
For this example I only needed to add one additional file, so the commandline was easy – if you need to add multiple files you may need to explore the /F switch and directive files. Or the features built into InstEd! to help with this (see their online help page).
makecab filename.xml LicenseFile.cab
Where filename.xml is the name of the license file and LicenseFile.cab is the name of the destination CAB file to be created.
InstEd! is a great little tool for editing MSI files. Its very similar in functionality to Orca if you have ever used that – but it is more user friendly and offers more functionality. The instructions provided assume you are using InstEd! There are two main methods you can use, edit the existing MSI – OR – create a transform file and reference it during the install. I will be creating a transform file, as I think if you edit an already signed MSI you will need to sign it again using certificates etc…
Create New Transform File
Open the MSI file in InstEd! and select Transform -> New Transform. Choose a filename for the new MST file. I called mine “LicenseFile.mst”
Add Component to component table
Go to the “Component” Table, right click in the rows pane on the right hand side and select “Add Row” – complete the details as follows :
|Component||LicenseFile (What you want the Component to be called)|
|ComponentId||(Use button to generate new GUID)|
|Directory||license_Dir (Use Directory Table to find name of desired target directory)|
|Attributes||0x0000 (Default value)|
I used an already existing entry in the Directory Table “license_Dir” – you may need to add a row to the directory table for your requirements.
The new row should now be visible and highlighted in green. The reason its green, is to show you which rows have been updated, added or deleted from the original MSI file by the transform file.
Associate the created component with a feature
Now we need to tell the MSI to install this new component when it installs the main application in my case this feature is called “MainFeature”.
|Feature||MainFeature (Choose appropriate feature from dropdown)|
|Component_||LicenseFile (Choose the component you created)|
Add the file entry in file table
Next we will add an entry in the file table for the actual file we want to add to the installation, in my case this is a license file which is getting installed to a subdirectory of the main program files folder. Luckily the developer of the application had anticipated people would want to install their license file during deployment so the MSI already had a directory entry for “license_Dir”. If this didnt exist we would need to create an entry in the Directory table as well.
Sort the “File” table by the field “Sequence” scroll to the bottom to find the highest sequence number and make a note of it (in my example the last Sequence number is 773, so my file will be 774). Add a row with the following values :
|File||filename.xml (The filename as stored in the CAB file)|
|Component||LicenseFile (Choose the component you created earlier)|
|FileName||filename.xml (The destination filename)|
Add the media entry in media table
The last table we need to edit in the MSI is the media table. This table tells the MSI where the files are to install, you will need the file sequence number from the previous step (774). I think the reason for this, is that when installers still came on disks this is the method by which the installer knew to ask for the next disk.
|DiskId||2 (My example already had a disk with id 1)|
|LastSequence||774 (LastSequence number of first disk + 1)|
Save and Test!
Once you have finished adding rows etc… you need to save the transform file. Just underneath the File and Edit menu should be a small box with the name of the mst file and a little asterix to indicate changes have been made. Right click this box and select save. Now you have saved the transform you can test the installation to see if it works. Put the *.mst and *.cab files in the same folder as the *.msi file and run the following commandline from an elevated (run as admin) command prompt.
msiexec /i filename.msi /qn /l*v %TEMP%\TransformTest.log TRANSFORMS=filename.mst
Note you do not need to reference the cab file in the commandline.
If all went well, the application plus the additional file should have installed succesfully – and a verbose msi install log will have been created in %TEMP% folder. Use this to troubleshoot any issues you encounter.