I have a setup project in Visual Studio 2008 with Custom Action class. I have to execute the msi on command line using msiexec /i SetupProject.msi /qb /l* out.txt command. The task is to write custom messages to the log file. This can be done by MsiProcessMessage function from Windows Installer API. To achieve this I have downloaded the C# wrapper class posted on CodeProject.com (http://www.codeproject.com/csharp/msiinterop.asp) that provides a C# interface to the common Windows Installer APIs.
Now the problem is, I am not able to get the MSIHANDLE for the current instance of the installer in custom action class using that wrapper class. My function Write to log goes like this,
private void WriteToLogFile(string sMessage)
{
IntPtr hInstall = IntPtr.Zero;
IntPtr hRec;
uint lCount;
MsiInterop.MsiOpenPackage(@" D:\SetupProject.msi", out hInstall);
//Validate the passed-in string
if (sMessage.Length == 0)
{
return;
}
//Create a record with only one field
hRec = MsiInterop.MsiCreateRecord(1);
//Handle problem creating record
if ((int)hRec == 0)
{
return;
}
//Create the full message
//szFullMessage = STARS + szMessage;
//Set that one field to the passed-in string
MsiInterop.MsiRecordSetString(hRec, 1, sMessage);
//Set the formatting string to NULL
MsiInterop.MsiRecordSetString(hRec, 0, "[1]");
//Get length of message to pass to MsiFormatRecord
lCount = (uint)sMessage.Length;
//Format the record to get rid of the '1.'
MsiInterop.MsiFormatRecord(hInstall, hRec, sMessage, ref lCount);
//Handle processing the message
MsiInterop.MsiProcessMessage(hInstall, MsiInstallMessage.Info, hRec);
}
In the above function, it neither takes any handle to the installer nor writes any thing to the log file.
Thanks in advance,
Yogita