What are the differences between INSTALLDIR and TARGETDIR?

Written by Horatiu Vladasel · August 26th, 2022

#MSI

In this article, we'll talk about how Windows Installer defines the directory location of an installation, what the INSTALLDIR and TARGETDIR properties are, and what is the difference between them.

First, let’s see where we can locate these directories.

What is the structure of an MSI install folder?

Each MSI package consists of a set of interrelated tables that contain all the information required for Windows Installer to install, uninstall or upgrade a corresponding application.

The tables within an MSI package are linked between them through primary and foreign key values and together comprise a relational database.

One of the most indispensable Windows Installer tables is the Directory table. As its name suggests, this table specifies the directory layout of an installation.

Each row of the Directory table indicates a directory and is resolved during the CostFinalize standard action. The Directory keys become properties set to directory paths.

ImportantThere might be scenarios where you need to change the directory location at the time of the installation using a command line, Custom Actions or straight from the installation wizard.

What is TARGETDIR in MSI installer?

The TARGETDIR property is one of the properties defined by Windows Installer and specifies the root destination directory for the installation. During an administrative installation, this is the location where the installation package gets copied.

ImportantThe Directory table must contain a single root destination directory – TARGETDIR.

In order to define the root destination directory, you must:

  • Set the Directory column to the TARGETDIR property.
  • Set the DefaultDIr column to the SourceDIr property.
Define Root Destination Directory

ImportantA Directory table entry that has a NULL value in the Directory_Parent column represents a root directory.

Then, the destination directory is resolved to the property’s value.

NoteIf the TARGETDIR property is not defined, then you can use the ROOTDRIVE property to resolve the path.

What is the difference between INSTALLDIR and TARGETDIR?

Unlike TARGETDIR, the INSTALLDIR property is specific to the MSI packages created with InstallShield only and specifies the product installation directory.

Same as TARGETDIR, the INSTALLDIR value (installation directory) can be changed via command line, custom actions or straight from the installation wizard.

By default, INSTALLDIR is defined in the Directory table as follows:

INSTALLDIR Definition in Directory Table

The period (.) in the DefaultDir column specifies that the directory should be located in its parent directory without a subdirectory.

The short file names specified in the DefaultDir column are used to resolve the destination directories if either the SHORTFILENAMES property is set or the target volume does not support long file names.

What is APPDIR in your MSI package?

APPDIR is the equivalent of INSTALLDIR in Advanced Installer. It comes with the same advantages – the installation directory can be changed using a command line, custom actions or straight from the installation wizard.

By default, APPDIR is defined in the Directory table as follows:

APPDIR Definition in Directory Table

Its value is then set to [ProgramFilesFolder][Manufacturer]\[ProductName] through the SET_APPDIR Custom Action.

SET_APPDIR Custom Action

NoteYou can easily define your Directory table using Advanced Installer’s GUI. Check out our 30-day full feature trial.

With both Advanced Installer and InstallShield, the property for defining the root destination for an installation is done through tables. However, if you're using a different tool that doesn't have a GUI, you will need to use scripts to define those properties.

How to create your installation directory in WiX?

WiX is one of the most popular tools for creating MSI installers, but it doesn't have a GUI. Because of that, all the information must be defined within the WiX source file, which is used to compile and then build the MSI installer.

As you may have guessed, the Directory element is the one that must be used to specify the directory layout of the installation along with the mappings between source and target directories.

Below, you can find an example of how to define your installation directory in WiX:

<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id='ProgramFilesFolder'>
<Directory Id='MyCompany' Name='MyCompany'>
<Directory Id='MYAPPDIR' Name='MyApp'>
<Component Id='MyComponent' Guid='{2D00166E-AAAA-4F24-B94F-3D5E9ED21D65}'> <File Id="Readme" Name="Readme.txt" DiskId="1" Source="Readme.txt"/>
</Component>
</Directory>
</Directory>
</Directory>
</Directory>

As you can see, the MYAPPDIR directory is the installation directory for the example above, but you could use any name you want for your application installer. Being a public property (all capital letters), the MYAPPDIR value can be changed via the command line.

Conclusion

TARGETDIR is one of the properties defined by Windows Installer. Additional properties can be authored by developers and/or IT Pros when defining the directory layout of the installation.

On top of that, tools like Advanced Installer or InstallShield come with their own automated solution to populate the Directory table based on the folder structure defined within the GUI.

Did you find this article helpful? Let us know in the comments below!

Subscribe to Our Newsletter

Sign up for free and be the first to receive the latest news, videos, exclusive How-Tos, and guides from Advanced Installer.

Comments: