如何生成mst文件作为2 msi文件的差异

时间:2016-01-21 14:01:45

标签: windows-installer msiexec

我在尝试更改msi文件后尝试生成mst文件。我的方法是这样的。

  1. 获取原始.msi文件的副本。
  2. 在msi文件副本中进行所有修改。
  3. 现在我有2个msi文件original.msi和modified.msi。有没有什么办法可以通过修改modified.msi-original.msi来生成.mst文件。我找到了installshield MsiDiff.exe的这个命令行工具来生成日志文件中的差异。有没有办法根据差异生成mst文件。

    "C:\Program Files\InstallShield\2014\System\MsiDiff.exe" "C:\InstallShield 2014 Projects\MyProject1.msi" "C:\InstallShield 2014 Projects\MyProject2.msi" /out "C:\Log File.xml"
    

    我正在寻找一个命令行工具,它将'orig.msi'和'modified.msi'作为输入,并可以生成差异作为mst文件。

1 个答案:

答案 0 :(得分:2)

来自windows sdk你得到这个vbs:

' Windows Installer utility to generate a transform from two databases
' For use with Windows Scripting Host, CScript.exe or WScript.exe
' Copyright (c) Microsoft Corporation. All rights reserved.
' Demonstrates use of Database.GenerateTransform and MsiDatabaseGenerateTransform
'
Option Explicit

Const msiOpenDatabaseModeReadOnly     = 0
Const msiOpenDatabaseModeTransact     = 1
Const msiOpenDatabaseModeCreate       = 3

If Wscript.Arguments.Count < 2 Then
    Wscript.Echo "Windows Installer database tranform generation utility" &_
        vbNewLine & " 1st argument is the path to the original installer database" &_
        vbNewLine & " 2nd argument is the path to the updated installer database" &_
        vbNewLine & " 3rd argument is the path to the transform file to generate" &_
        vbNewLine & " If the 3rd argument is omitted, the databases are only compared" &_
        vbNewLine &_
        vbNewLine & "Copyright (C) Microsoft Corporation.  All rights reserved."
    Wscript.Quit 1
End If

' Connect to Windows Installer object
On Error Resume Next
Dim installer : Set installer = Nothing
Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError

' Open databases and generate transform
Dim database1 : Set database1 = installer.OpenDatabase(Wscript.Arguments(0), msiOpenDatabaseModeReadOnly) : CheckError
Dim database2 : Set database2 = installer.OpenDatabase(Wscript.Arguments(1), msiOpenDatabaseModeReadOnly) : CheckError
Dim transform:transform = ""  'Simply compare if no output transform file supplied
If Wscript.Arguments.Count >= 3 Then transform = Wscript.Arguments(2)
    Dim different:different = Database2.GenerateTransform(Database1, transform) : CheckError
If Not different Then Wscript.Echo "Databases are identical" Else If transform = Empty Then Wscript.Echo "Databases are different"

Sub CheckError
    Dim message, errRec
    If Err = 0 Then Exit Sub
    message = Err.Source & " " & Hex(Err) & ": " & Err.Description
    If Not installer Is Nothing Then
        Set errRec = installer.LastErrorRecord
        If Not errRec Is Nothing Then message = message & vbNewLine & errRec.FormatText
    End If
    Wscript.Echo message
    Wscript.Quit 2
End Sub

脚本有3个参数:原始数据库,更新数据库,最后第3个是mst完整路径