Redigera

Dela via


Returning Error Messages from Custom Actions

This section describes how to send messages from custom actions that actually perform a part of the installation by calling a dynamic link library or script. Note that Custom Action Type 19 only sends a specified error message, returns failure, and then terminates the installation. Custom Action Type 19 does not perform any part of the installation.

To send an error message from a custom action that uses a dynamic-link library (DLL), have the custom action call MsiProcessMessage. Note that custom actions launched by a DoAction ControlEvent can send messages with the Message method but cannot send a message with MsiProcessMessage. On systems earlier than Windows Server 2003, custom actions launched by a DoAction ControlEvent cannot send messages with MsiProcessMessage or Message method. For more information, see Sending Messages to Windows Installer Using MsiProcessMessage.

To display an error message from within a custom action using a DLL

  1. The custom action should call MsiProcessMessage and pass in the parameters hInstall, eMessageType, and hRecord. The handle to the installation, Custom Action Type 19, may be provided to the custom action as described in Accessing the Current Installer Session from Inside a Custom Action or from MsiOpenProduct or MsiOpenPackage.
  2. The parameter eMessageType should specify one of the message types as listed in MsiProcessMessage.
  3. The hRecord parameter of the MsiProcessMessage function depends upon the message type. See Sending Messages to Windows Installer Using MsiProcessMessage. If the message contains formatted data, enter the message into the Error table using the formatting described in Formatted.

To send an error message from a custom action that uses Scripts, the custom action may call the Message method of the Session object.

To display an error message from within a custom action using script

  1. The custom action should call the Message method of the Session object and pass in the parameters kind and record.
  2. The parameter kind should specify one of the message types listed in the Message method.
  3. The record parameter of the Message method depends upon the message type. If the message contains formatted data, enter the message into the Error table using the formatting described in Formatted.

Custom actions using Executable Files cannot send a message by calling MsiProcessMessage or the Message method because they cannot get a handle to the installation.

Custom Action Return Values