prasadus92
Posts: 58
Joined: Wed Feb 25, 2015 8:10 am

How to pass Windows Installer properties to a WiX C# Custom action?

Sun Aug 30, 2015 4:31 pm

Hi,

I need to pass [Installed], [REINSTALL] and [UPGRADINGPRODUCTCODE] to a WiX C# custom action. How to include this in "Action data"? I tried using

Code: Select all

param1=value1;param2=value2
, but these properties are coming as empty string in my custom action code. If I put some dummy string for

Code: Select all

param1=value1
, value1 is available in my custom action. Not sure whether or not we can send these Windows Installer properties.

My use case is that, in my custom action, I need to know whether install or uninstall or upgrade is happening and take appropriate actions for that.

Thanks in advance.
Prasad

Dan
Posts: 4513
Joined: Wed Apr 24, 2013 3:51 pm

Re: How to pass Windows Installer properties to a WiX C# Custom action?

Mon Aug 31, 2015 7:05 am

Hi Prasad,

In order to retrieve or set windows installer properties, please take a look on the Retrieving and setting properties article with related information for hints and guidance.

If you have other questions, please let us know.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

prasadus92
Posts: 58
Joined: Wed Feb 25, 2015 8:10 am

Re: How to pass Windows Installer properties to a WiX C# Custom action?

Wed Sep 02, 2015 5:42 am

Hi Dan,

Thanks for your reply.

Looks like the documentation that you have mentioned explains about passing a single property as a parameter. I wanted to know if there is a way to pass multiple properties to a custom action.

Thanks
Prasad

Dan
Posts: 4513
Joined: Wed Apr 24, 2013 3:51 pm

Re: How to pass Windows Installer properties to a WiX C# Custom action?

Wed Sep 02, 2015 12:04 pm

Hi Prasad,

If your custom action is of immediately one, then you don't have to pass installer properties through the CustomActionData property. In the immediately custom actions you can retrieve installer properties as explain in the Retrieving and setting properties article.

Indeed, if the custom action is of deferred type, then you can pass installer properties through the CustomActionData property. For details, please check the Pass installer properties in deferred custom action article.

To pass multiple properties, you can add them as following:
ActionData InstallerProps.png
ActionData InstallerProps.png (12.08KiB)Viewed 11281 times
To retrieve the CustomActionData, you can use the following statement:

Code: Select all

string aCustomActionData = session.CustomActionData.ToString();
Please note that the aCustomActionData string will contain both ProductName and ProductVersion values separated by comma.
e.g.
MsgBox ActionData.png
MsgBox ActionData.png (13.69KiB)Viewed 11281 times
Here's the full code of my sample custom action:

Code: Select all

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
using System.Windows.Forms;

namespace DeferredCA_SampleProj
{
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult aDeferredCustomAction(Session session)
        {
            try
            {
                session.Log("Begin aDeferredCustomAction");

                // retrieving the value of the CustomActionData property
                string aCustomActionData = session.CustomActionData.ToString();

                MessageBox.Show("aCustomActionData sting contains:  \n\n" + aCustomActionData, "Action Data Value");

                session.Log("End aDeferredCustomAction");
            }
            catch (Exception ex)
            {
                session.Log("Error in custom action aDeferredCustomAction {0}", ex.ToString());

                return ActionResult.Failure;
            }

            return ActionResult.Success;
        }
    }
}
If you have other questions, please let me know.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”