49

I want to install an MSI file with msiexec into a specific directory. I am using:

msiexec /i "msi path" INSTALLDIR="C:\myfolder" /qb

Using "INSTALLDIR" is not working properly because the MSI is installed into the default path and not into the specified path.

Josh Correia
  • 3,807
  • 3
  • 33
  • 50
Cataldo
  • 515
  • 1
  • 4
  • 7
  • 1
    What made you think it would work with INSTALLDIR? Do you know what tool the MSI file was built with? – Samir Apr 08 '19 at 15:13
  • `INSTALLDIR` does not appear in the Windows documentation. Source: https://learn.microsoft.com/en-us/windows/win32/msi/property-reference – user894319twitter Nov 07 '22 at 09:58

13 Answers13

55

Use TARGETDIR instead of INSTALLDIR. Note that the quote marks for TARGETDIR property are only around the path in the case of spaces.

msiexec /i "msi path" TARGETDIR="C:\myfolder" /qb

Source: https://learn.microsoft.com/en-us/windows/win32/msi/targetdir

Ciprian
  • 3,533
  • 1
  • 18
  • 22
16

InstallShield 12

INSTALLDIR represents the main product installation directory for a regular Windows Installer–based (or InstallScript MSI) installation, such as the end user launching Setup.exe or your .msi database.

TARGETDIR represents the installation directory for an InstallScript installation, or for an administrative Windows Installer based installation (when the user runs Setup.exe or MsiExec.exe with the /a command-line switch).

In an InstallScript MSI project, the InstallScript variable MSI_TARGETDIR stores the target of an administrative installation.

Source: INSTALLDIR vs. TARGETDIR

user2226755
  • 12,494
  • 5
  • 50
  • 73
David Schwartz
  • 181
  • 1
  • 3
  • 2
    This appears to have been taken from https://helpnet.flexerasoftware.com/installshield21helplib/helplibrary/FAQFilesInstallDirs.htm?. – Marc.2377 Nov 01 '19 at 21:53
15

Use INSTALLLOCATION. When you have problems, use the /lv log.txt to dump verbose logs. The logs would tell you if there is a property change that would override your own options. If you already installed the product, then a second run might just update it without changing the install location. You will have to uninstall first (use the /x option).

ezzadeen
  • 1,033
  • 10
  • 9
  • 1
    This is really just a complement to other answers here; but +1 for the `/lv` and `/x` hints. – tripleee Oct 30 '19 at 07:48
  • This is really the best answer because it resolves how to specify the install directory for **any** application. Use log.txt to determine the appropriate property to set for your application. – Shane Gramlich Jun 27 '20 at 01:42
  • 1
    This is the best answer (/lv log.txt) as the property name may vary greatly. In my case, it was APPLICATIONFOLDER. – Fonic Sep 07 '20 at 20:00
  • `INSTALLLOCATION` does not appear in the Windows documentation. Source: https://learn.microsoft.com/en-us/windows/win32/msi/property-reference – user894319twitter Nov 07 '22 at 09:47
10
msiexec /i "msi path" INSTALLDIR="C:\myfolder" /q

Only this variant worked well.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Moscow Boy
  • 1,591
  • 3
  • 14
  • 15
  • `INSTALLDIR` does not appear in the Windows documentation. Source: https://learn.microsoft.com/en-us/windows/win32/msi/property-reference – user894319twitter Nov 07 '22 at 09:48
9

In my case all of them did not work and finally it was

msiexec /i "msinamebla.msi" INSTALLFOLDER="C:\test\" /qb

I checked the log.txt as described by ezzadeen and found "INSTALLFOLDER" in there.

Colibri
  • 713
  • 12
  • 16
  • 2
    This worked for me as well. What property name you use depends largely on what tool was used to build the MSI file. My MSI file was built using WiX 3.11.1 and it appears that INSTALLFOLDER is the property name that's used by WiX, while TARGETDIR is used by others. – Samir Apr 08 '19 at 15:21
  • Also, make sure to use fully qualified paths. Otherwise it may fail with a warning saying that it "could not access network location". This is true for both INSTALLFOLDER with `/i` and for TARGETDIR with `/a`. – Samir Apr 08 '19 at 15:26
  • 1
    I came to the same conclusion as you and found that only the use of `INSTALLFOLDER` worked in my batch installation. Strangely enough, this property is not documented on MSN: [Property Reference](https://learn.microsoft.com/en-us/windows/win32/msi/property-reference). – Andreas Nov 11 '21 at 10:28
  • `INSTALLFOLDER` does not appear in the Windows documentation. Source: https://learn.microsoft.com/en-us/windows/win32/msi/property-reference – user894319twitter Nov 07 '22 at 09:47
4

Actually, both INSTALLPATH/TARGETDIR are correct. It depends on how MSI processes this.

I create a MSG using wixToolSet. In WXS file, there is "Directory" Node, which root dir maybe like the following:

<Directory Id="**TARGETDIR**" Name="SourceDir">;

As you can see: Id is which you should use.

Unheilig
  • 16,196
  • 193
  • 68
  • 98
xiaoym
  • 41
  • 2
  • `INSTALLDIR` does not appear in the Windows documentation. Source: https://learn.microsoft.com/en-us/windows/win32/msi/property-reference – user894319twitter Nov 07 '22 at 09:51
3

This should work:

msiexec /i "msi path" TARGETDIR="C:\myfolder" /qb
Shibiraj
  • 769
  • 4
  • 9
2

Use APPLICATIONFOLDER="path" for latest msiexec

Sharvin K
  • 697
  • 3
  • 10
  • `APPLICATIONFOLDER` does not appear in the Windows documentation. Source: https://learn.microsoft.com/en-us/windows/win32/msi/property-reference – user894319twitter Nov 07 '22 at 09:45
  • It works for me when I try to install pandoc using chocolatey, when INSTALLDIR, TARGETDIR and INSTALLPATH all failed – shiratori3 Mar 18 '23 at 08:53
1

This one worked for me too

msiexec /i "msi path" INSTALLDIR="D:\myfolder" /q

I had tried two other iterations and both installed in the default C:\Program Files

INSTALLDIR="D:\myfolder" /q got it installed on the other drive.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
ttoomm
  • 11
  • 1
  • `INSTALLDIR` does not appear in the Windows documentation. Source: https://learn.microsoft.com/en-us/windows/win32/msi/property-reference – user894319twitter Nov 07 '22 at 09:52
1

for my msi, I had to set DEFAULTPATHC="D:\myfolder" because later in the installation process, both INSTALLDIR and TARGETDIR were reset to reflect the value in DEFAULTPATHC

  • `INSTALLDIR` does not appear in the Windows documentation. Source: https://learn.microsoft.com/en-us/windows/win32/msi/property-reference – user894319twitter Nov 07 '22 at 09:51
1

I tried TARGETDIR, INSTALLLOCATION and INSTALLDIR args and still it installed in the default directory. So I viewed the log and there is this arg where it sets the Application Directory and it is being set to default.

MSI (s) (50:94) [09:03:13:374]: Running product '{BDAFD18D-0395-4E72-B295-1EA66A7B80CF}' with elevated privileges: Product is assigned.
MSI (s) (50:94) [09:03:13:374]: PROPERTY CHANGE: Adding APPDIR property. Its value is 'E:\RMP2'.
MSI (s) (50:94) [09:03:13:374]: PROPERTY CHANGE: Adding CURRENTDIRECTORY property. Its value is 'C:\Users\Administrator'.

So I changed the command to have APPDIR instead of the args mentioned above. It worked like a charm.

msiexec /i "path_to_msi" APPDIR="path_to_installation_dir" /q

Add /lv if you want to copy the installation progress to a logfile.

sriramsm04
  • 343
  • 1
  • 7
  • 22
  • `INSTALLDIR` does not appear in the Windows documentation. Source: https://learn.microsoft.com/en-us/windows/win32/msi/property-reference – user894319twitter Nov 07 '22 at 09:51
0

If you've used Advanced Installer to build your .msi you will want to use APPDIR=

Shawn J. Molloy
  • 2,457
  • 5
  • 41
  • 59
0

Here's my attempt to install .msi using msiexec in Administrative PowerShell.

I've made it 7 times for each of 2 drives, C: and D: (14 total) with different arguments in place of ARG and the same desirable path value.

Template: PS C:\WINDOWS\system32> msiexec /a D:\users\username\downloads\soft\publisher\softwarename\software.msi /passive ARG="D:\Soft\publisher\softwarename"

ARGs:

  • TARGETDIR
    • Works OK-ish, but produces redundand ProgramFilesFolder (with an additional folders similar to the default installation path, e.g. D:\Soft\BlenderFoundation\Blender\ProgramFilesFolder\Blender Foundation\Blender\2.81\) and a copy of the .msi at the target folder.
  • INSTALLDIR, INSTALLPATH, INSTALLFOLDER, INSTALLLOCATION, APPLICATIONFOLDER, APPDIR
  • When running on the same drive as set in the parameter: installs on this drive in a default folder (e.g. D:\Blender Foundation\Blender\2.81\)
  • When running from a differnet drive: seems to do nothing

You may try ARPINSTALLLOCATION (docs).

VELFR
  • 407
  • 5
  • 21