Kae Travis

Writing to the Windows Installer log file from a Custom Action

This blog entry provides an example of writing to the windows installer log file from a custom action using VBScript. It follows on from the previous blog post which provided a tutorial on using SQL inside an MSI database custom action using VBScript.

It forms part 15 of an 17-part series that explores how to use VBScript to manipulate MSI relational databases using the Windows Installer API. Throughout this series of tutorials, we identify the common issues that we encounter and the best practises that we use to overcome them.

Logging is extremely useful when debugging MSIs. Most people that write Custom Actions don’t write logs, but if you’re writing quite extensive logic you may wish to consider it. Simply paste the following logic into your CA:

'Subroutine to write to log file 
Const msiMessageTypeInfo = &H04000000
Sub writeToLog(ByVal msg)
Set record = Installer.CreateRecord(1)
record.stringdata(0) = "AlkaneLog: [1]"
'This value gets subbed in to the [1] placeholder above
record.stringdata(1) = msg
record.formattext
message msiMessageTypeInfo, record
Set record = Nothing
End Sub

and write to the log like this:

writeToLog("This is a log message")

Thanks for reading about writing to the Windows Installer log file from a Custom Action using VBScript. Next you can find out how to edit MSI files in the windows installer cache using VBScript.

Writing to the Windows Installer log file from a Custom Action
Writing to the Windows Installer log file from a Custom Action

2 thoughts on “Writing to the Windows Installer log file from a Custom Action

Leave a Reply