Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6031713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:13:33+00:00 2026-05-23T05:13:33+00:00

I have a WiX installer and a single custom action (plus undo and rollback)

  • 0

I have a WiX installer and a single custom action (plus undo and rollback) for it which uses a property from the installer. The custom action has to happen after all the files are on the hard disk. It seems that you need 16 entries in the WXS file for this; eight within the root, like so:

<CustomAction Id="SetForRollbackDo" Execute="immediate" Property="RollbackDo" Value="[MYPROP]"/>
<CustomAction Id="RollbackDo" Execute="rollback" BinaryKey="MyDLL" DllEntry="UndoThing" Return="ignore"/>
<CustomAction Id="SetForDo" Execute="immediate" Property="Do" Value="[MYPROP]"/>
<CustomAction Id="Do" Execute="deferred" BinaryKey="MyDLL" DllEntry="DoThing" Return="check"/>
<CustomAction Id="SetForRollbackUndo" Execute="immediate" Property="RollbackUndo" Value="[MYPROP]"/>
<CustomAction Id="RollbackUndo" Execute="rollback" BinaryKey="MyDLL" DllEntry="DoThing" Return="ignore"/>
<CustomAction Id="SetForUndo" Execute="immediate" Property="Undo" Value="[MYPROP]"/>
<CustomAction Id="Undo" Execute="deferred" BinaryKey="MyDLL" DllEntry="UndoThing" Return="check"/>

And eight within the InstallExecuteSequence, like so:

<Custom Action="SetForRollbackDo" After="InstallFiles">REMOVE&lt;>"ALL"</Custom>
<Custom Action="RollbackDo" After="SetForRollbackDo">REMOVE&lt;>"ALL"</Custom>
<Custom Action="SetForDo" After="RollbackDo">REMOVE&lt;>"ALL"</Custom>
<Custom Action="Do" After="SetForDo">REMOVE&lt;>"ALL"</Custom>
<Custom Action="SetForRollbackUndo" After="InstallInitialize">REMOVE="ALL"</Custom>
<Custom Action="RollbackUndo" After="SetForRollbackUndo">REMOVE="ALL"</Custom>
<Custom Action="SetForUndo" After="RollbackUndo">REMOVE="ALL"</Custom>
<Custom Action="Undo" After="SetForUndo">REMOVE="ALL"</Custom>

Is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:13:34+00:00Added an answer on May 23, 2026 at 5:13 am

    I came across the same problem when writing WiX installers. My approach to the problem is mostly like what Mike suggested and I have a blog post Implementing WiX custom actions part 2: using custom tables.

    In short, you can define a custom table for your data:

    <CustomTable Id="LocalGroupPermissionTable">
        <Column Id="GroupName" Category="Text" PrimaryKey="yes" Type="string"/>
        <Column Id="ACL" Category="Text" PrimaryKey="no" Type="string"/>
        <Row>
            <Data Column="GroupName">GroupToCreate</Data>
            <Data Column="ACL">SeIncreaseQuotaPrivilege</Data>
        </Row>
    </CustomTable>
    

    Then write a single immediate custom action to schedule the deferred, rollback, and commit custom actions:

    extern "C" UINT __stdcall ScheduleLocalGroupCreation(MSIHANDLE hInstall)
    {
        try {
            ScheduleAction(hInstall,L"SELECT * FROM CreateLocalGroupTable", L"CA.LocalGroupCustomAction.deferred", L"create");
            ScheduleAction(hInstall,L"SELECT * FROM CreateLocalGroupTable", L"CA.LocalGroupCustomAction.rollback", L"create");
        }
        catch( CMsiException & ) {
            return ERROR_INSTALL_FAILURE;
        }
        return ERROR_SUCCESS;
    }
    

    The following code shows how to schedule a single custom action. Basically you just open the custom table, read the property you want (you can get the schema of any custom table by calling MsiViewGetColumnInfo()), then format the properties needed into the CustomActionData property (I use the form /propname:value, although you can use anything you want).

    void ScheduleAction(MSIHANDLE hInstall,
                const wchar_t *szQueryString,
                const wchar_t *szCustomActionName,
                const wchar_t *szAction)
    {
        CTableView view(hInstall,szQueryString);
        PMSIHANDLE record;
    
        //For each record in the custom action table
        while( view.Fetch(record) ) {
            //get the "GroupName" property
            wchar_t recordBuf[2048] = {0};
            DWORD    dwBufSize(_countof(recordBuf));
            MsiRecordGetString(record, view.GetPropIdx(L"GroupName"), recordBuf, &dwBufSize);
    
            //Format two properties "GroupName" and "Operation" into
            //the custom action data string.
            CCustomActionDataUtil formatter;
            formatter.addProp(L"GroupName", recordBuf);
            formatter.addProp(L"Operation", szAction );
    
            //Set the "CustomActionData" property".
            MsiSetProperty(hInstall,szCustomActionName,formatter.GetCustomActionData());
    
            //Add the custom action into installation script. Each
            //MsiDoAction adds a distinct custom action into the
            //script, so if we have multiple entries in the custom
            //action table, the deferred custom action will be called
            //multiple times.
            nRet = MsiDoAction(hInstall,szCustomActionName);
        }
    }
    

    As for implementing the deferred, rollback and commit custom actions, I prefer to use only one function and use MsiGetMode() to distinguish what should be done:

    extern "C" UINT __stdcall LocalGroupCustomAction(MSIHANDLE hInstall)
    {
        try {
            //Parse the properties from the "CustomActionData" property
            std::map<std::wstring,std::wstring> mapProps;
            {
                wchar_t szBuf[2048]={0};
                DWORD dwBufSize = _countof(szBuf); MsiGetProperty(hInstall,L"CustomActionData",szBuf,&dwBufSize);
                CCustomActionDataUtil::ParseCustomActionData(szBuf,mapProps);
            }
    
            //Find the "GroupName" and "Operation" property
            std::wstring sGroupName;
            bool bCreate = false;
            std::map<std::wstring,std::wstring>::const_iterator it;
            it = mapProps.find(L"GroupName");
            if( mapProps.end() != it ) sGroupName = it->second;
            it = mapProps.find(L"Operation");
            if( mapProps.end() != it )
                bCreate = wcscmp(it->second.c_str(),L"create") == 0 ? true : false ;
    
            //Since we know what opeartion to perform, and we know whether it is
            //running rollback, commit or deferred script by MsiGetMode, the
            //implementation is straight forward
            if( MsiGetMode(hInstall,MSIRUNMODE_SCHEDULED) ) {
                if( bCreate )
                    CreateLocalGroup(sGroupName.c_str());
                else
                    DeleteLocalGroup(sGroupName.c_str());
            }
            else if( MsiGetMode(hInstall,MSIRUNMODE_ROLLBACK) ) {
                if( bCreate )
                    DeleteLocalGroup(sGroupName.c_str());
                else
                    CreateLocalGroup(sGroupName.c_str());
            }
        }
        catch( CMsiException & ) {
            return ERROR_INSTALL_FAILURE;
        }
        return ERROR_SUCCESS;
    }
    

    By using the above technique, for a typical custom action set you can reduce the custom action table to five entries:

    <CustomAction Id="CA.ScheduleLocalGroupCreation"
                  Return="check"
                  Execute="immediate"
                  BinaryKey="CustomActionDLL"
                  DllEntry="ScheduleLocalGroupCreation"
                  HideTarget="yes"/>
    <CustomAction Id="CA.ScheduleLocalGroupDeletion"
                  Return="check"
                  Execute="immediate"
                  BinaryKey="CustomActionDLL"
                  DllEntry="ScheduleLocalGroupDeletion"
                  HideTarget="yes"/>
    <CustomAction Id="CA.LocalGroupCustomAction.deferred"
                  Return="check"
                  Execute="deferred"
                  BinaryKey="CustomActionDLL"
                  DllEntry="LocalGroupCustomAction"
                  HideTarget="yes"/>
    <CustomAction Id="CA.LocalGroupCustomAction.commit"
                  Return="check"
                  Execute="commit"
                  BinaryKey="CustomActionDLL"
                  DllEntry="LocalGroupCustomAction"
                  HideTarget="yes"/>
    <CustomAction Id="CA.LocalGroupCustomAction.rollback"
                  Return="check"
                  Execute="rollback"
                  BinaryKey="CustomActionDLL"
                  DllEntry="LocalGroupCustomAction"
                  HideTarget="yes"/>
    

    And InstallSquence table to only two entries:

    <InstallExecuteSequence>
        <Custom Action="CA.ScheduleLocalGroupCreation" 
                After="InstallFiles">
            Not Installed
        </Custom>
        <Custom Action="CA.ScheduleLocalGroupDeletion" 
                After="InstallFiles">
            Installed
        </Custom>
    </InstallExecuteSequence>
    

    In addition, with a little effort most of the code can be written to be reused (such as reading from custom table, getting the properties, formatting the needed properties and set to CustomActionData properties), and the entries in the custom action table now is not application specific (the application specific data is written in the custom table), we can put custom action table in a file of its own and just include it in each WiX project.

    For the custom action DLL file, since the application data is read from the custom table, we can keep application specific details out of the DLL implementation, so the custom action table can become a library and thus easier to reuse.

    This is how currently I write my WiX custom actions, if anyone knows how to improve further I would very appreciate it. 🙂

    (You can also find the complete source code in my blog post, Implementing Wix custom actions part 2: using custom tables.).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using WiX (Windows Installer XML) I have created an MSI installer which installs Word
I have a fairly complicated installer that I'm writing in Wix that has a
I've got a WiX installer project which uses MSBuild to generate the MSI file.
I have a Wix installer which should be allowed to run on Windows Server
I have a WiX installer which needs to install new bits for Interop.FOOBARLib.DLL to
I have a WIX Installer project, which installs my product. The code was not
I have a WiX installer which sets up a couple of root IIS websites
I'm creating a Wix installer for a windows service which needs to have provided,
I have a WiX installer project that utilises a custom dialog box to ask
We currently have a Database Project, which we wrote a WIX Installer for to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.