Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
440 views
in Technique[技术] by (71.8m points)

scripting - Script to change Action Sequence records in an MSI

To solve a problem listed here I've got to change the InstallExecuteSequence .RemoveExistingProducts record in an MSI.

I want to do this as part of the build process rather than mucking around with Orca

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Modifying the MSI_SetProperty.js script gives

// 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);
}

To call this script to perform the change to the action sequence mentioned above you would put the following in a batch file and call that from the post build event e.g. PostBuildEvent = $(ProjectDir)PostBuild.bat

cscript.exe MSI_SetActionSequence.js YOURINSTALLER.MSI InstallExecuteSequence RemoveExistingProducts 1525

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...