Link: http://teach.hanzify.org/article/652-1233562028.html
Preface
Recently, a Chinese friend asked me how to replace the files in the MSI installation program without making the MSI file again. To this end, I will summarize my practical experience for your reference. Please correct me for any errors.
※Description:
There are a lot of software that can be used for MSI editing at present, but some software will write some of its own tables or content into the MSI file during storage, and some will embed another cab file, increase the number of MSI files. The method provided here ensures that no unnecessary content or files are written.
※Key points:
1. The file sequence in the cab must be consistent with that in the MSI file table.
2. Some files in the cab use file names that are not supported by windows.
Software preparation
1. orca: MSI editor provided by Microsoft. Chinese version (version 4.5.6001.22192 ):
Http://www.hanzify.org/index.php? Go = show: List & id = 11122 or
Http://www.wanfutrade.com/software/hanhua/Orca45chs.msi
2. msidb, a tool for extracting and replacing CAB files in MSI provided by Microsoft. My Chinese version (version 4.5.6001.22192 ):
Http://www.wanfutrade.com/software/hanhua/MsiDb.exe
3. iexpress: A cab file packaging user interface tool provided by Microsoft. My Chinese version (version 6.0.0.0 ):
Http://www.wanfutrade.com/software/hanhua/iexpress20.exe
4. Excel. I believe everyone has this. Any version is supported.
Basic knowledge
1. MSI file format
The MSI file is actually an installation database with many tables. These tables are all text written in the tab format, just like excel, which consists of columns and rows. You can export each table from MSI. The exported table can be opened in a text editor or Excel. The role of each field in each table and table is not described here. Please refer to the relevant information provided by Microsoft.
2. MSI Installation File Format
There are many types of files to be installed in the MSI Installer. The following are common examples:
(1) The installation file is packaged as a cab file and embedded in the MSI file.
(2) The installation file is packaged as a cab file, but the cab exists independently of MSI.
(3) The installation file is not packaged as a cab file, but exists in various folders in the original state.
For cab files in the form of (1) and (2), you can replace them with the methods described in this article, and directly replace the files in the form of (3.
3. MSI Installation File List
There are two tables in the MSI file that are used to express the file list and the name and number of files and other information in the cab. These are the file table and media table, the file table stores the file names in the cab, the components of each file, the actual file names after installation, the file size, version, language, attributes, and file sequence, the media table stores information such as the disk ID, number of files, disk description, cab file name, and volume label of the cab file.
Let's take a look at the two tables in the MSI file:
(1) file table
The above is the file table. The columns related to this topic are described as follows:
File column, indicating the list of file names in the cab. Some are common file name formats. Some are added with numbers like class IDs after common file names, and some are simply numbers. For the reason why common file names are not used, I think some MSI production software deliberately named this name for some purpose. In particular, the MSI file created by InstallShield.
Compoent _ column, indicating which component the file belongs.
Filename column, indicating the file name after installation. Where | the front is the short file name, followed by the long file name.
Filesize column, indicating the file size. You do not need to change it, even if the replaced file is inconsistent with it.
Language column, indicating the language used by the file. Generally, you do not need to change it, even if the replaced file language is different from the original one.
The attributes column indicates the attributes of a file, such as hidden, system, and archive. Generally, you do not need to change it unless you have a special purpose, such as hiding a file after installation.
The sequenec column indicates the sequence number of the file. The sequence number must start from 1.
(2) Media table
In the media table, diskid, diskprompt, volumelable, and source columns do not need to be considered. Here we mainly introduce the other two columns below.
The lastsequence column indicates the number of files in the cab, that is, the maximum number in the sequenec column in the preceding file table. The two numbers must be consistent.
The Cabinet column, indicating the cab file name. Note: The "#" before the file name is not part of the real file name.
Start practice
1. Extract the cab file embedded in MSI. Skip this operation if the cab file is independent of MSI.
Use the dig msidb.exe-x cab file name-d msi file name command under dosor msidb.exe.
Here: (1) the cab file name is the cab file name in the cabinet column in the media table. Ignore the prefix "#".
(2) Both the cab and MSI file names must have a suffix extension.
2. Use Windows resource manager or RAR or other compression software to Extract files from the cab file to a separate folder.
3. Run the CMD command to go To the DOS interface. In the separate folder where the files in the cab are released, run the "DIR/B> cabfilelist.xls" command to extract the list of file names in the folder. You can replace the cabfilelist.xls file name with other file names.
4. Use msidb.exe or Orca to open the MSI file and export the file table in the MSI file. The exported file name is file. IDT.
5. Open the file. IDT file in Excel and sort the entire table by sequenec column. For example.
6. Compare whether the number of files extracted from the cab is equal to the number of files listed in the file table in the MSI file. You can directly search for the msifile and the released folder, or you can use excelto separately open the cabfilelist.xls and file. IDT.
(1) If they are equal, the file names are generally the same.
(2) If not, it indicates that some files in the cab have names that are not recognized by the Windows system. For example, there are files in the cab such as XXX. (note the file names after XXX.
In a new column in the condition, use the IF function to determine whether the two are different. (Note the file with. In the msi_filetable_filelist column ).
7. In the extracted folder, add a number or something after the file name of a different file and rename it, then, extract another file from the cab file.
8. Insert a worksheet in cabfilelist.xls to sort the files in step 1. copy the file column and sequenec column of the IDT file to the new worksheet, and add columns such as "file", ", and" = "to other columns, then, use the concatenate Text Merge function to merge the data in these columns into the script format required by iexpress ..
9. Replace the files that have been extracted with the obtained files (Note: there are differences in steps 6th and 7 ).
※We recommend that you directly convert the files that have been decompressed in Chinese to avoid the trouble of renaming them.
10. Run iexpress and select the "Create compressed file only" option () to add all or part of the files that have been replaced by Chinese to the files to be packaged, select the "save file with long file name" option in the software package and save the file. the iexpress script file with the SED extension.
11. Modify the iexpress script file. Open the saved iexpress script file (. sed), and copy the SED [Strings] column from the Excel table in step 2 to the [Strings] section of the iexpress script file. Similarly, copy the SED [sourcefiles0] column to the [sourcefiles0] section.
※Important:
If a different file exists in steps 2 and 7, see [Strings] of the iexpress script file, name the different files according to the names of the files in the MSI file (the names of files in the MSI are used in step 1, so you do not need to modify them here ). Change all the file names in the [sourcefiles0] section of the iexpress script file to the actual file names that exist in the resource manager.
※Remarks:
(1) There is no file name after "=" in the [sourcefiles0] section of the general iexpress script file (. Sed. Because different file names exist, special processing is required here.
(2) When you create a cab, the program automatically deletes all file names in [sourcefiles0. Save the backup and copy it back at the next creation.
12. Run iexpress again, open the modified iexpress script file, and go to the next step. A new cab file that matches the file sequence in the file table in the MSI file that has been replaced by the file after the Chinese version is used is generated.
13. Insert the new cab file into the MSI file. Skip this operation if the cab file is independent of MSI.
First, use the dig msidb.exe-K cab file name-d msi file name command under dosor msidb.exe to delete the cab file in the MSI file (in fact, only the association is cleared ). Use the unzip msidb.exe-A cab file name-d msi file name command to insert a new cab file to the MSI file.
Here: (1) the cab file name is the cab file name in the cabinet column in the media table. Ignore the prefix "#".
(2) Both the cab and MSI file names must have a suffix extension.
If the result is unsuccessful, use the "cmdmsidb.exe-K cab file name-D msifile name" command to clear the flow, and then use "cmdmsidb.exe-A cab file name-d msi file name" to add a new cab file.
Note: msidb.exe does not support some long folder names and an error is prompted. We recommend that you use the short folder name whenever possible.
14. installation and testing. Run the installation program to check whether errors such as "file does not exist" will occur during the installation process. If no errors exist, you will be done.
Remarks
1. Thank you for reading this article. It will be a great pleasure to help you.
2. The copyright of this article belongs to Wanfu. You are welcome to repost this article without modification.
3. Contact Email: [email protected]
About compression ratio
1. By default, the compression ratio of CAB files made with iepress is relatively low. In the initial test, iepresssupports all parameters of makecab.exe. You only need to add compressiontype = LZX in the [Options] section to achieve LZX compression.
2. According to the prompts of zhfi users, I checked the relevant information and used cabarc.exe-M LZX: the 21-R n cab file name "file directory \ *" command can indeed obtain a higher compression rate than iepress, and there is no sequence problem. However, if there is an MSI with xxx. this file does not exist after being decompressed. such files cannot be packaged into new cab files that are the same as those of the original cab, you can only solve this problem by modifying the file name in the file column of the file table in the MSI file and the file name associated with other tables.
3. According to the Chinese friends "fish" method, you can use the following command line in the folder where the file to be compressed is located:
Makecab/F <full path> msifilelist.txt/d compressiontype = LZX/d compressionmemory = 21/D maxdisksize = 1024000000/d diskdirectorytemplate = Data */d cabinetnametemplate = Data *. Cab
Here: msifilelist.txt refers to the file name list of the file column in the file table in the MSI file (sort by sequenec column from small to large ),
Diskdirectorytemplate = Data * in data *, that is, when the volume is compressed, data1/data2/data3… is generated under the folder where the file to be compressed is located ...... Folder. Only one folder is generated when no volume is compressed.
Cabinetnametemplate = Data *. Cab data *. Cab, that is, when the volume is compressed, data1/data2/data3 ...... Folder to generate cab file names such as data1.cab/data2.cab/data3.cab.
However, if the original cab contains XXX. and XXX files with the same file name after decompression, this method is not applicable.
4. If you have deleted some files in the cab and modified the MSI table (if not modified, an installation error will occur !), To reduce the size of the msifile, use orcato open the msifile, and then use msidb.exe to insert a new cab. Note
Download the entire file: replace. MHT with the file in the MSI Installer