change installer properties in C# custom action

白昼怎懂夜的黑 提交于 2019-12-04 04:00:36

To access a WiX property, such as those set with the Property element, use the Session object's indexer. Here is an example:

[CustomAction]
public static ActionResult CustomAction1(Session session)
{
string myProperty = session["MY_PROPERTY"];
return ActionResult.Success;
}

Setting properties is just as easy. You'll set the value by referencing the key with the name of your property. Here's an example:

[CustomAction]
public static ActionResult CustomAction1(Session session)
{
session["MY_PROPERTY"] = "abc";
return ActionResult.Success;
}

If the property doesn't exist when you set it, it will be created. Similarly, you can clear a property by setting its value to null. Creating or changing property values from a custom action doesn't stop the installer from displaying those properties in the install log. So, if a property holds information that ought to be hidden, you're better off declaring it in your WiX markup first and setting its Hidden attribute to yes.

<Property Id="MY_PROPERTY" Hidden="yes" />

You can't. Only Win32 DLLs and VBScript Immediate actions have write access to installer properties. Any other custom action type can only receive properties through their command line or through CustomActionData.

Here is a tutorial for a C++ DLL custom action: http://www.codeproject.com/KB/install/msicustomaction.aspx

To get and set Windows Installer properties you can use MsiGetProperty() and MsiSetProperty().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!