Windows Installer API (SDK)

CustomAction Table

Referenz » CustomAction Table | Microsoft Docs


The CustomAction table provides the means of integrating custom code and data into the installation. The source of the code that is executed can be a stream contained within the database, a recently installed file, or an existing executable file.

Column Type Key Nullable
Action Identifier Y N
Type Integer N N
Source CustomSource N Y
Target Formatted N Y
ExtendedType DoubleInteger N Y

VBS class CustomAction


Class classCustomActionTable
Private mAction, mType, mSource, mTarget, mExtendedType

    Public Property Get pAction
        pAction = mAction
    End Property
    Public Property Let pAction(strAction)
        mAction = strAction
    End Property
    Public Property Get pType
        pType = mType
    End Property
    Public Property Let pType(intType)
        mType = intType
    End Property
    Public Property Get pSource
        pSource = mSource
    End Property
    Public Property Let pSource(strSource)
        mSource = strSource
    End Property
    Public Property Get pTarget
        pTarget = mTarget
    End Property
    Public Property Let pTarget(strTarget)
        mTarget = strTarget
    End Property
    Public Property Get pExtendedType
        pExtendedType = mExtendedType
    End Property
    Public Property Let pExtendedType(intExtendedType)
        mExtendedType = intExtendedType
    End Property
    
    Private Sub Class_Initialize
        'Anweisungen
    End Sub
    ' -----------------------------------------------------------------



    Public Function ModifyCustomActionRecord()
    Dim strSQL, objView, objTableRow

    strSQL = "SELECT * FROM CustomAction"

    Set objView = objDatabase.OpenView(strSQL)
    objView.Execute
    Do 
        Set objTableRow = objView.Fetch
        If objTableRow Is Nothing Then
            Set objTableRow = objInstaller.CreateRecord(5)
            objTableRow.StringData(1) = mAction
            objTableRow.IntegerData(2) = mType
            objTableRow.StringData(3) = mSource
            objTableRow.StringData(4) = mTarget
            If Not IsNull(mExtendedType) Then _
                objTableRow.IntegerData(5) = mExtendedType
            objView.Modify msiViewModifyAssign, objTableRow
            Exit Do
        End If
        objTableRow.StringData(1) = mAction
        objTableRow.IntegerData(2) = mType
        objTableRow.StringData(3) = mSource
        objTableRow.StringData(4) = mTarget
        If Not IsNull(mExtendedType) Then _
            objTableRow.IntegerData(5) = mExtendedType
        objView.Modify msiViewModifyAssign, objTableRow
    Loop
    objDatabase.Commit()
    objView.Close
    Set objView = Nothing

    End Function
    ' -----------------------------------------------------------------



    Public Function TaskKill(TaskName)

    mAction = "CA_TaskKill_" & Trim(TaskName)
    mType = cInt("3170")
    mSource = "SystemFolder"
    mTarget = "Taskkill.exe /F /IM " & Chr(34) & TaskName & Chr(34)
    mExtendedType = Null

        ModifyCustomActionRecord

    msiInstallExecuteSequence.pAction = mAction
    msiInstallExecuteSequence.pCondition = ""
    msiInstallExecuteSequence.pSequence = cInt("1010")

        msiInstallExecuteSequence.ReorderInstallExecuteSequenceTable "AfterInstallInitialize" ' 1010
        msiInstallExecuteSequence.ModifyInstallExecuteSequenceRecord

    End Function
    ' -----------------------------------------------------------------



    Public Function ServiceDelete(ServiceName)

    mAction = "CA_ServiceDelete_" & ServiceName
    mType = cInt("3170")
    mSource = "SystemFolder"
    mTarget = "sc.exe delete " & Chr(34) & ServiceName & Chr(34)
    mExtendedType = Null

    ModifyCustomActionRecord

    msiInstallExecuteSequence.pAction = mAction
    msiInstallExecuteSequence.pCondition = "REMOVE~=" & Chr(34) & "ALL" & Chr(34)
    msiInstallExecuteSequence.pSequence = cInt("2004")

    msiInstallExecuteSequence.ReorderInstallExecuteSequenceTable "AfterCA_ServiceStop_" & ServiceName
    msiInstallExecuteSequence.ModifyInstallExecuteSequenceRecord
    
    End Function
    ' -----------------------------------------------------------------



    Private Sub Class_Terminate()
        'Anweisungen
    End Sub
End Class
' ---------------------------------------------------------------------