cancel
Showing results for 
Search instead for 
Did you mean: 

PowerShell Trace-info Cmdlet Does Not Write To Log

No ratings

PowerShell Trace-info Cmdlet Does Not Write To Log

Summary

This article explains why the PowerShell trace-info cmdlet does not write to the log when the action is called from a DoAction ControlEvent.

Question

Why does the trace-info cmdlet fail to write to the Windows Installer log file when a PowerShell custom action is launched from a DoAction ControlEvent?


Here is an example of how you might use the trace-info cmdlet in a PowerShell custom action to write to the log file:
trace-info ?LogMessage ?I am a PowerShell custom action?

Answer

This is due to a limitation of the DoAction ControlEvent in Windows Installer. The Windows Installer API function that is used by the trace-info cmdlet to add messages to the log file is MsiProcessMessage. This function is not available when launched from a DoAction control event. This is documented here https://msdn.microsoft.com/en-us/library/windows/desktop/aa368322(v=vs.85).aspx. If you launch your PowerShell action as part of the installation sequence (immediate or deferred), you should see the message added to the log

The above link regarding the DoAction limitation does explain that you can use the Message method from a DoAction control event. Unfortunately, PowerShell does not have access to the Windows Installer Session object (with the Message method belongs to) so you cannot use this with a PowerShell custom action.

VBScript custom actions for example do have access to the Session object. If it's critical to write to the log from a custom action launched by a DoAction ControlEvent, here's a quick example of some VBScript which uses Session.Message to write to the log:


Const msiMessageTypeInfo = &H04000000

' create the message record
Set msgrec = Installer.CreateRecord(1)

' field 0 is the template
msgrec.StringData(0) = "Log: [1]"

' field 1, to be placed in [1] placeholder
msgrec.StringData(1) = "Calling LoggingTestVBS..."

' send message to running installer
Session.Message msiMessageTypeInfo, msgrec

Related Documents

Labels (1)
Was this article helpful? Yes No