views:

99

answers:

1

action1How do I set a MSI property from within a C# custom action, so far I have this but how do I get the 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 the CA from WiX with the following line

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

and the action1 looks like this

public class CustomActions
{
    [CustomAction]
    public static ActionResult action1(Session session)
    {
        session.Log("Begin action1");
        SetProperty("xyz", "123");
    }
} 
+2  A: 

You should be able to set a 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'm sure he'll be along soon to comment on this one.

fletcher
Now I feel like a question troll. <grin/>In DTF we don't have access to the handle because technically we are running out of process from MSI. The session object is our proxy over an IPC back to an unmanaged dll and it's handling all of our P/Invoke interop for us. One other tip, handles do still exist though so make sure you take advantage of the various IDispose implementations in DTF by placing objects such as database views and records inside Using() blocks. When the object goes out of scope it'll call Dispose() which will cause the unmanaged side to close the various MSI handles.
Christopher Painter
Since you've done C++ type 1 CA's you are no doubt aware of the funky things MSI can do when you fail to close handles.
Christopher Painter
Your comments are really informative, I've been learning alot about WiX from this site... we're nearly shot of InstallShield!
fletcher