Tuesday, December 18, 2012

Writing custom strings to MSI Log File

Its a general practise to create a log file for troubleshooting installation related issues. By default installshield writes log file but it does not contain the logs related to our own created custom actions. We could write our own strings to the msi file by using SprintfMsiLog. 

For this we need to declare the prototype and defintion of our installscript code as below:

Custom action name: LoggingCustomAction

Code:
#include "ifx.h"
//prototype
export prototype LoggingCustomAction(HWND);

//custom action definition
function LoggingCustomAction(hLogInstall)
begin
    SprintfMsiLog("Writing Custom Log...");
    //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...