Monday, November 17, 2008

Expanding properties at run time


MSI database fields that use the Formatted data type can take expressions of the form [PropertyName], and the value will be expanded at run time. The [expression] doesn’t need to be the whole field; for example, you can put the following in a registry value and the appropriate parts of the oddly phrased sentence will be expanded at run time:

Installed to [INSTALLDIR] by [USERNAME] from account [LogonUser] at [Time] on [Date].

As with all things property-related, capitalization (and spelling) matter.

You can tell the data type of a field by looking at the Windows Installer help library topic for the given table. The topic “Registry Table” indicates that the Name and Value fields use the Formatted data type, which means that property values contained in those fields will be expanded. On the other hand, the Name and Description fields of the Shortcut table use other data types (Filename and Text), and therefore don’t expand properties.

(See the topic “Formatted” for other expressions that will get expanded, such as [%ENV_VAR] for environment variables and [\[] and [\]] for literal square-bracket characters.)

While we’re on the subject, a field that uses the Identifier data type doesn’t need square brackets around it. For example, the DirProperty field of the RemoveFile table accepts a directory property such as AppDataFolder, and does not take brackets.

No comments: