scripting - 更改MSI中 Action 序列记录的脚本

标签 scripting build-process windows-installer

为了解决listed here问题,我必须更改MSI中的InstallExecuteSequence .RemoveExistingProducts记录。

我想将其作为构建过程的一部分,而不是与Orca混为一谈

最佳答案

修改MSI_SetProperty.js脚本可以得到

// MSI_SetActionSequence.js <msi-file> <table> <action> <sequence>
// Performs a post-build fixup of an msi to set the specified table/action/sequence

// Constant values from Windows Installer SDK
var msiOpenDatabaseModeTransact = 1;

var msiViewModifyInsert         = 1;
var msiViewModifyUpdate         = 2;
var msiViewModifyAssign         = 3;
var msiViewModifyReplace        = 4;
var msiViewModifyDelete         = 6;

if (WScript.Arguments.Length != 4)
{
    WScript.StdErr.WriteLine("Usage: " + WScript.ScriptName + " file table action sequence");
    WScript.Quit(1);
}

var filespec = WScript.Arguments(0);
var table = WScript.Arguments(1);
var action = WScript.Arguments(2);
var sequence = parseInt(WScript.Arguments(3));

var installer = WScript.CreateObject("WindowsInstaller.Installer");
var database = installer.OpenDatabase(filespec, msiOpenDatabaseModeTransact);

WScript.StdOut.WriteLine("Looking for action:" + action);

try
{   
    var sql = "SELECT Action, Sequence FROM " + table + " WHERE Action = '" + action + "'";
    var view = database.OpenView(sql);  

    view.Execute();     
    var record = view.Fetch();  

    if (record)
    {       
        while (record)
        {
            WScript.StdOut.Write("Found: " + record.StringData(0) + ", " + record.StringData(1) + ", " + record.StringData(2));
            if (record.IntegerData(2) != sequence)
            {
                WScript.StdOut.WriteLine(" - changing to " + sequence);
                record.IntegerData(2) = sequence;
                view.Modify(msiViewModifyUpdate,record);
            }
            else
                WScript.StdOut.WriteLine(" - OK");

            record = view.Fetch();
        }

        view.Close();
        database.Commit();
    }
    else
    {           
        view.Close();   
        throw("Warning - Could not find " + table + "." + action);
    }
}
catch(e)
{
    WScript.StdErr.WriteLine(e);
    WScript.Quit(1);
}

要调用此脚本以执行上述操作顺序的更改,您需要将以下内容放入批处理文件中,并从构建后事件中调用该文件,例如PostBuildEvent = $(ProjectDir)PostBuild.bat
cscript.exe MSI_SetActionSequence.js YOURINSTALLER.MSI InstallExecuteSequence RemoveExistingProducts 1525

关于scripting - 更改MSI中 Action 序列记录的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/617409/

相关文章:

wix - 使用 DTF 的消息框

scripting - 使用 VBScript 读取 CSV 文件

c++ - VC++ express,我该如何解决这个错误?

java - 限制 Java 包之间的依赖关系

java - 专业的Java/JavaScript工具箱

powershell - 如何找到已安装的MSI设置的产品GUID?

php - Filemtime/cachetime 我哪里出错了?

PHP Azure WebJob - 失败并退出代码 255(但在 Kudu 上工作正常)

windows - 在批处理脚本之后继续使用 CMD 命令

installation - 运行 RemovePreviousVersion 时,MSI 不会安装所有文件