1

My MSI installation needs to be two-phase. In the first I collect data from user, and in the second one I want to run the actual installation using the collected values from the 1st phase. The 2nd phase needs to be run in elevated context.

I found on the Web that the only way to pass values to the elevated deffered action is to set properties. In MSDN article (and also on some examples over the web) it is said that I need to

  • set property [named the same as the "primary key" of the deffered action] - with the value to be passed to the deffered action. Specifically, the value can be in the form of key=value string format, repeated and semicolon delimited.
  • fetch values in the deffered action using the indexer (passing the keys).

I start off with the actions definition:

project.Actions = new []
        {
            new ManagedAction(InstallerActions.LiveBankInstallPrepare, Return.check, When.After, Step.InstallExecute, 
                Condition.Always, Sequence.InstallExecuteSequence)
            { 
                ActionAssembly = "%this%", 
                Name = "Preparing installation",
            }, 
            new ElevatedManagedAction(InstallerActions.LiveBankInstallExecute, Return.check, When.After, Step.InstallExecute, 
                Condition.Always, Sequence.InstallExecuteSequence)
            { 
                ActionAssembly = "%this%", 
                Name = "Executing installation",
                Id = "ABCD" 
            }, 
        };

Having collected the data in the 1st action I store it in the property named the same as the ID of the deffered action

propertyDict = BuildSemicolonSeparatedDict();
session["ABCD"] = propertyDict;

//at runtime propertyDict is e.g. execMode=InstallForced; timeout=5

The question that I have is:

What am I doing wrong, that I can not see in the deffered action the propertyDict assigned in the first step (action).

var execMode = session.CustomActionData["execMode"];
//key not found in the dictionary, however propertyDict built in the first action contains it. 

I guess I must be passing the value wrong, as when I statically set the action parameters with UsesProperties property, I can see the key-value pairs in the deffered action.

Michal.Jan008
  • 135
  • 11

3 Answers3

1

It's actually easier than you think when using ManagedUI. The CustomUIDialog example shows how to set a test value in a form and retrieve it in AfterInstall action.

You are most likely experiencing an issue with the deferred execution of the custom action (some actions are deferred like AfterInstall) where session values / properties are not available anymore.

Here is a hint from the author itself.

ViRuSTriNiTy
  • 5,017
  • 2
  • 32
  • 58
0

No a direct solution, but it worked for me: In the first action I collect some data... and serialize as key-value pairs string. Than save to a file. In the second action I do the reverse process - read the file, deserialize - and have the values in the target deffered action.

Michal.Jan008
  • 135
  • 11
0

You Need to declare those Properties in your WixSharp Project. For Ex.

project.Properties.Add(new Property("Test", "Test"));

Then you can Reference it in your CustomAction/Elevated Custom Action

                new ElevatedManagedAction {
                MethodName = "Test",
                Return = Return.check,
                When = When.Before,
                Step = Step.InstallFinalize,
                Condition = Condition.NOT_Installed,
                Impersonate = false,
                Execute = Execute.deferred,
                UsesProperties = "Test"
            }

Now you should be able to use it in your Custom Actions / Set it in your UI via MSIRuntime etc. Thats the possibility I know.

wwe
  • 1