MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: Features[Next]: GUIDS
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Windows Installer FAQ (the basics)->Formatted Strings

Windows Installer Basics: Formatted Strings

Some table columns support formatting which can be used to replace "codes" (variables) with their contents, the following describes the basics only see the SDK doco for more information.

Code Description
[PropertyName] Replaced with the property's value. Unmatched brackets ignored. If the "PropertyName" is invalid then the string is left in place, if the property is null (empty) an empty string is used. remember that property names are case sensitive and only public (upper case) properties can be specified on the command line.

You should also have a look at the "Sample Properties" section. You can of course create your own properties (for example with FileFind or RegistryRead). See the "trailing slash removal" example for how an existing property is modified (in this case you don't want a slash on the end of a file's path).

[DirectoryKey] Works much like propery replacement above, this value is replaced with the installtime directory's value (which always ends with a "\", need to trim with a custom action if this is an issue).

In actual fact this is property replacement as Windows Installer creates properties for directory keys which allows their values to be specified on command lines etc.

[%EnvironmentVariable] Replaced with the environment variables value.
[#FileKey] Replaced with the filename of the specified file (long format).
[!FileKey] Replaced with the filename of the specified file (8.3 format). Note that this format only returns the 8.3 formatted file name for the "Value" column in the "Registry" or "IniFile" tables, otherwise the long format is used (as if "[#FileKey]" were used).
[$ComponentKey] Replaced with the components installation directory. This can evaluate to a empty string in some circumstances.
[\SingleChar] Replaced with the character specified, can be used to enter brackets and other difficult characters that might otherwise cause a "BADFORMATTED" (Windows Installer) error.

Some examples of the character ("escape") codes you should use:

  • For [ use [\[]
  • For ] use [\]]
[~] Replaced with a null character (0x00). This is used to author REG_MULTI_SZ character strings in the "Registry" table. Note that "[~]" is also used to append or prefix values to environment variables using the "Environment" table.

There are restrictions on where some of the above codes can be used, please see the SDK doco for more information.

Test the use of any formatting well, including tests for:

  1. Normal Installation
  2. User invoked repair (maintenance dialog)
  3. Any maintenance processes you intend to use in future
  4. Installation on demand (use application under multiple users)
  5. Normal Uninstallation

I recommend that if you use the "Path" command that you check the relevant environment variables after each of the tests, see:

For backwards compatability reasons some MAKEMSI commands support Windows Installer formatting by default while others like the "registry" command don't (and use the MSIFORMATTED" parameter to turn it on).

BADFORMATTED - Incorrectly Formatted Strings

If incorrect MSI formatting is supplied to a table column that supports formatting then Windows Installer will complain with something similar to:

...
REASON
~~~~~~~
Windows Installer has reported that 1 column(s) in a "Registry" table
record failed "FIELD" validation:

    * #1 "Value": (BADFORMATTED) An invalid formatted string was supplied. You probably
need to "escape" characters such as curley or square brackets (encode "[" as "[\[]" etc).

Contents of the Problem Record (table "Registry")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Registry (s72) = RegKey803
Root (i2) = 0
Key (l255) = VisualStudio.inc.8.0
Name (L255) = <<null string>> (OK: nulls allowed in this column)
Value (L0) = PHP C"N<?[h XNSvgt@C<
Component_ (s72) = C_INC_FILETYPE

In the above Japanese text the "[" character needs to be replaced with "[\[]" (that is it needs to be escaped as documented above).

As the registry" command was most likely used to generate the failing table manipulation, you can also use its "MSIFORMATTED" parameter to tell it that the text you passed was unformatted and MAKEMSI will do any required character escaping for you.

An example of a command that will generate this sort of error is:

<$Component "INI" Create="Y" Directory_="<$AnyDir>" LM="Y">
   <$IniFile "Dennis.INI" DIR="INSTALLDIR">
       <$IniSection "Section1">
           <$Ini "Key1" Value="Some [value">
       <$/IniSection>
   <$/IniFile>
<$/Component>

To correct it change the "ini" command to:

<$Ini "Key1" Value="Some [\[]value">

Some other links about this or similar issues:

Alternatives

Note that not all Windows Installer columns support MSI formatting. With other tools, MSI formatting is the only way to insert replaceable information, this is not the case with MAKEMSI as a lot of information can be determined or is known and generally available in PPWIZARD macros, some examples follow:


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Features[Next]: GUIDS


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Sunday February 28 2016 at 3:45pm
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.