Monday, November 17, 2008

InstallScript Custom Actions


In an InstallScript custom action, you can call SprintfMsiLog to write a string to the MSI log

file. For example, the following InstallScript code prototypes and defines an InstallScript

custom action called LoggingTestInstallScript.

#include "ifx.h"

// standard custom action prototype

export prototype LoggingTestInstallScript(HWND);

// custom action definition

function LoggingTestInstallScript(hInstall)

begin

SprintfMsiLog("Calling LoggingTestInstallScript...");

// return success to MSI

return ERROR_SUCCESS;

end;

In order to be called, the custom action must be scheduled in the sequences. For this

example, open the Custom Actions view and create an immediate-mode InstallScript custom

action called callLoggingTest that calls the LoggingTestInstallScript function, and schedule it

to run after LaunchConditions.

After building the package and running it with the /L*v switch, you should see a line similar

to the following in the log file:

InstallShield 25:00:00: Invoking script function LoggingTestInstallScript

1: Calling LoggingTestInstallScript...

InstallShield 25:00:00: CallScriptFunctionFromMsiCA() ends

Action ended 25:00:00: callLoggingTest. Return value 1.

The SprintfMsiLog function is similar to the Sprintf and SprintfBox functions, in that you can

include placeholders ("%s" or "%d" fields, called "format specifiers") in the message string

if you want to splice in the values of string or numeric variables.

No comments: