MsiSetProperty from C # Custom Action

action1 How do I set the MSI property from a custom C # action, as long as I have it, but how do I get a handle?

[DllImport("msi.dll", CharSet = CharSet.Unicode)]
static extern int MsiSetProperty(IntPtr hInstall, string szName, string szValue);

public void SetProperty(string propertyName, string propertyValue)
{
    MsiSetProperty(handle, propertyName, propertyValue);
}

I am calling CA from WiX with the following line

<CustomAction Id="CA1" BinaryKey="ca1.dll" DllEntry="action1" />

and action1 looks like this:

public class CustomActions
{
    [CustomAction]
    public static ActionResult action1(Session session)
    {
        session.Log("Begin action1");
        SetProperty("xyz", "123");
    }
} 
+3
source share
1 answer

You should be able to set the property by doing the following:

public class CustomActions 
{ 
    [CustomAction] 
    public static ActionResult action1(Session session) 
    { 
        string xyzProperty = "XYZ";

        session[xyzProperty] = "ABC";
    } 
} 

See Christopher Painter's post here:

http://blog.deploymentengineering.com/2008/05/deployment-tools-foundation-dtf-custom.html

I am sure he will comment on this one soon.

+4
source

Source: https://habr.com/ru/post/1755945/


All Articles