brad
Posts: 5
Joined: Thu Sep 05, 2024 2:41 am

Value passing between custom actions

Hi

I am having trouble passing values between custom actions.

I have a Powershell script inline which is deferred and I want to pass a value from it to a C# Call function from attached native DLL, also deferred.

In an effort to ensure I have a property to set, I have created a custom action installer property whose name is in all caps (a public property?). In the below code I have called it MYPUBLICPROPERTY.

I have other values successfully being passed to the C# CA DLL but, for the life of me, I cannot figure how to get a value out of the Powershell script and into the action data of the call to the DLL.

Here's the powershell inline script I have:

Code: Select all

#Requires -version 3
Param(  )

function Get-SomethingFromCommandLine {
    [array] $cmdOutput = (my command)

    Foreach ($placeholder IN $cmdOutput)
    {
        if ($var1 -match "thingy") {
            # Set-Property -name "MYPUBLICPROPERTY" -value $var1
            AI_SetMsiProperty MYPUBLICPROPERTY $var1
            write-output $var1
        }
    }
}

Has anyone got a fix or a an approach I can try?

# Your code goes here
Get-SomethingFromCommandLine
And this is the Action Data for the C# CA DLL:

Code: Select all

userData=[THISPROPWORKS1]	[THISPROPWORKS2]	[THISPROPWORKS3]	[THISPROPWORKS4]	[THISPROPWORKS5]	[THISPROPWORKS6]	[MYPUBLICPROPERTY]


I have tried using the session object from the C# custom action but apparently you can't access session variables from a Deferred Custom Action. The error I get is this;

Code: Select all

Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> WixToolset.Dtf.WindowsInstaller.InstallerException: Cannot access session details from a non-immediate custom action
   at WixToolset.Dtf.WindowsInstaller.Session.ValidateSessionAccess()
   at WixToolset.Dtf.WindowsInstaller.Session.get_Item(String property)
   at BradsCustomAction.CustomActions.CustomAction1(Session session)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
   at WixToolset.Dtf.WindowsInstaller.CustomActionProxy.InvokeCustomAction(Int32 sessionHandle, String entryPoint, IntPtr remotingDelegatePtr)
CustomAction BradsCustomAction.CA.dll returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 12:17:56: InstallExecute. Return value 3.
Daniel
Posts: 8276
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Value passing between custom actions

Hi,

This approach does not work because during a deferred custom action you cannot set an installer property. Only from an immediate action you can set an installer property.

The correct approach would be to try writing your value in a temp resource (e.g. registry, file) and then accessing it from your C# custom action and clean up the temp resource after reading it.

Let me know if this works for you.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
brad
Posts: 5
Joined: Thu Sep 05, 2024 2:41 am

Re: Value passing between custom actions

Excellent.

Thank you for confirmation of this behaviour.

I have attempted to use the registry but am bumping into a problem with getting my installer to use the 64-bit registry. Things appear to be landing in WOW6432, even though I have set the Powershell custom action to use x64. If I compile my C# custom action to x64 only I get problems being able to load the CA DLL.

Is there a good how-to somewhere on making Advanced Installer only deal with 64-bit?

Cheers
Daniel
Posts: 8276
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Value passing between custom actions

Hi,

You should be able to write in the 64-bit section of the registry as long as your PowerShell custom action is configured to use the "x64" platform. I have just tested this and successfully ran and created the 64-bit registry.
screen1.png
screen1.png (106.1 KiB) Viewed 6720 times

Can you try to use the New-ItemProperty cmdlet and let me know if this helps?

Otherwise maybe you can try to replicate the issue you are facing with into a small sample and share it with us. If you do not want to attach it on this forums thread, then you can email it at support at advancedinstaller dot com.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”