Some Place In Space

Rambling thoughts and ideas I hope you find useful or amusing.

  • Categories

  • Archives

Adding Managed Custom Actions to the ProgressBar

Posted by taocoyote on 19/05/2009


With DTF

using System.Threading;
using Microsoft.Deployment.WindowsInstaller;
using System.Windows.Forms;

namespace CustomAction {
public class CustomActions {

// Specify or calculate the number of ticks in an increment
// to the ProgressBar
const uint iTickIncrement = 10000;

// Specify or calculate the total number of ticks the custom
// action adds to the length of the ProgressBar
const uint iNumberItems = 10;
const uint iTotalTicksiTickIncrementiNumberItems;

public static ActionResult CAProgressSession session ) {

// Tell the installer to check the installation state and execute
// the code needed during the rollback, acquisition, or
// execution phases of the installation.

ifsession.GetModeInstallRunMode.Scheduled ) ) {

Record hActionRecnew Record( 3 );
Record hProgressRecnew Record( 3 );

// Installer is executing the installation script. Set up a
// record specifying appropriate templates and text for
// messages that will inform the user about what the custom
// action is doing. Tell the installer to use this template and
// text in progress messages.

hActionRec[1] = “MyCustomAction”;
hActionRec[2] = “Incrementing the Progress Bar…”;
hActionRec[3] = “Incrementing tick [1] of [2]”;
MessageResult iResultsession.MessageInstallMessage.ActionStarthActionRec );
if( ( iResult == MessageResult.Cancel ) ) {
return ActionResult.UserExit;

// Tell the installer to use explicit progress messages.
hProgressRec[1] = 1;
hProgressRec[2] = 1;
hProgressRec[3] = 0;
iResultsession.MessageInstallMessage.ProgresshProgressRec );
if( ( iResult == MessageResult.Cancel ) ) {
return ActionResult.UserExit;

//Specify that an update of the progress bar’s position in
//this case means to move it forward by one increment.
hProgressRec[1] = 2;
hProgressRec[2] = iTickIncrement;
hProgressRec[3] = 0;

// The following loop sets up the record needed by the action
// messages and tells the installer to send a message to update
// the progress bar.

hActionRec[2] = iTotalTicks;

forint i = 0; iiTotalTicksi += (int)iTickIncrement ) {
hActionRec[1] = i;

iResultsession.MessageInstallMessage.ActionDatahActionRec );
if( ( iResult == MessageResult.Cancel ) ) {
return ActionResult.UserExit;

iResultsession.MessageInstallMessage.ProgresshProgressRec );
if( ( iResult == MessageResult.Cancel ) ) {
return ActionResult.UserExit;

//A real custom action would have code here that does a part
//of the installation. For this sample, code that installs
//10 registry keys.
Thread.Sleep( 1000 );

return ActionResult.Success;
else {
// Installer is generating the installation script of the
// custom action.

// Tell the installer to increase the value of the final total
// length of the progress bar by the total number of ticks in
// the custom action.
Record hProgressRecnew Record( 2 );

hProgressRec[1] = 3;
hProgressRec[2] = iTotalTicks;
MessageResult iResultsession.MessageInstallMessage.ProgresshProgressRec );
if( ( iResult == MessageResult.Cancel ) ) {
return ActionResult.UserExit;
return ActionResult.Success;

Then in WiX (or whatver):

<CustomAction Id=”caSetup” BinaryKey=”CustomAction.CA.dll” DllEntry=”CAProgress” Execute=”immediate”/>
<CustomAction Id=”caGo” BinaryKey=”CustomAction.CA.dll” DllEntry=”CAProgress” Execute=”deferred”/>

<Custom Action=”caSetup” Before=”InstallFinalize”>NOT Installed</Custom>
<Custom Action=”caGo” After=”caSetup”>NOT Installed</Custom>

Can’t seem to get the action text to update though. I just get the time left.

Edit: I now think something has to subscribe to ActionText and ActionData. This means making a custom ProgressDlg in Wix, since the one provided with UIExtension only shows the description from ActionStart (actionRecord[2] above).

Edit2: I am happily surprised to see that this has been useful to some people. I put it here more as a reminder to myself. I will have to clean this post up a bit.
Also: Yes this does work for me and on the dozens of VM’s I have tested it on. Not claiming that this is perfect or correct however.



One Response to “Adding Managed Custom Actions to the ProgressBar”

  1. Juan C. Becerra said

    Thanks for the code. I’ve been trying it (with InstallShield), but unfortunately it only updates the text on the dialog and I never see any progress on the progress bar. Any idea on how to fix it?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: