Msi CustomAction

From wikinotes

CustomActions allow you to run external scripts during your install process.
Depending on the ActionType, it's source may be embedded within the table, stored in a CAB file, or something else entirely.

Simply creating a CustomAction entry does not make it run. You must also add it to one/all of the Msi Sequences tables.

NOTE:

This is also the safest way of setting the TARGETDIR property to something sensible.

Documentation

CustomAction Ref https://docs.microsoft.com/en-us/windows/win32/msi/customaction-table
Sequence Tables

Example

action_data = [('SetTargetDirAction',    # name
                51,                      # type (set property from formatted string)
                'TARGETDIR',             # source (name of property)
                r'[AppDataFolder]\tma')] # target (the formatted string)
msilib.add_data(db, 'CustomAction', action_data)
db.Commit()

execute_data = [('SetTargetDirAction', 'Not TARGETDIR Or TARGETDIR=ROOTDRIVE', 990)]  # Sequence must be lower than 'CostFinalize' action (1000)
msilib.add_data(db, 'InstallExecuteSequence', execute_data)
msilib.add_data(db, 'AdminExecuteSequence', execute_data)
msilib.add_data(db, 'InstallUISequence', execute_data)
msilib.add_data(db, 'AdminUISequence', execute_data)
db.Commit()