Geeks With Blogs

Arthur Zubarev Compudicted
Yesterday I was doing an upgrade to a product and I needed to install it into the path where the old version used to be. I only needed to figure out what install option I need.
 
I knew MS Installer supports a vast number of command line options, I hoped that it will be easy to find the correct one, but looking into the MSDN’s help did not help finding the necessary Public Property right away, it simply was not immediately obvious.
So I tried one property then another and finally in frustration decided to turn on the logging to see what the MSI package is doing when I change the default destination path.
Examining the produced file immediately yielded results – bingo, the right property was very evident, buried in the middle of my install log - TARGETDIR. The rest was easy:
I created a custom command line install directive
msiexec /passive TARGETDIR="C:\MyTagretDirectory" /i MyProject.msi
And was able to get the desired path pre-populated!
 Install Path
In my case I did not want the user to interact with the installer and therefore added the /passive option which reduces the MS Installer GUI to merely a progress bar.
Posted on Tuesday, February 17, 2009 1:31 PM | Back to top


Comments on this post: Forcing MSI Installation Into a Specific Directory

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
thanks.. installation to target folder worked successfully
Left by umesh manilal on Jun 18, 2009 8:09 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
thanks Arthur, you are a god. I was ready to start pulling my hair after reading all the official MS documentation on msiexec, and trying things on my own. I never would have imagined that something so trivial could go unmentioned.
Left by Max on Nov 17, 2009 12:26 PM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
Thanks Arthur! Just perfect!
Left by Christine on Nov 24, 2009 6:14 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
MyProject.msi TARGETDIR="C:\MyTagretDirectory"
This also yields the same result
Left by Sandeepan Kundu on Dec 10, 2009 6:41 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
Perfect! You're my hero.
Left by Jonathan on Feb 05, 2010 11:55 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
I'd like to use TARGETDIR="D:\Program Files" but it doesn't seem to work. Anybody know if TARGETDIR should let you specify a drive other than C:?
Left by Jessica on Jun 02, 2010 8:08 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
, I found that INSTALLDIR does the trick for me. Even though I was specifying TARGETDIR=”D:\Program Files”, the install was continuing to install to C:\Program Files. However, INSTALLDIR=”D:\Program Files” does install to the D drive for me.
Left by Jessica on Jun 02, 2010 10:30 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
I had no idea that you could force the installer to take the path of any chosen directory. This could prove to come in handy when you want to install something that no one else can find.
florist Phoenix AZ
Left by ArchieOtto on Jul 19, 2010 7:59 PM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
INSTALLDIR worked well for me. I needed to script the installation of VMware Tools to "D:\Program Files\VMware Tools"

Thanks Jessica
Left by AG on Nov 17, 2010 4:44 PM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
Where to add this command line in my project or elsewhere..
Left by bobby on Jan 28, 2011 9:03 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
You can create a BAT file to install and then further customizations are easy, however you can also do the same in the Post Build Step using VS as described here: http://visualstudiohacks.com/general/customize-your-project-build-process/#
Left by Arthur on Jan 31, 2011 3:50 PM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
Hi Arthur ,
I created a bat file with msiexec command as mentioned and hooked it with PostBuildEvent. But this only works while builing the setup project to msi . this is not getting fired when we try to install the msi .

my doubt is how you hooked this command line directive while installing the msi ?
Left by Jerin on Mar 01, 2011 1:11 PM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
I just want to confirm that INSTALLDIR works on Windows 7 ( 64bit). Thanks for this post.
Left by Marcin on May 07, 2011 1:24 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
Unfortunately, I have no Windows 7 64 Bit to try, could you just experiment and get back?
Left by Arthur on May 10, 2011 12:19 PM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
Yes, It is working. I have searched many other but failed.
Left by Sanket on May 30, 2011 8:15 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
How can we use the above command in vbscript. I am installing a msi using vbscript and want to give the installation path??? how to use it in vbscript?
Left by Twikle on Oct 14, 2011 1:19 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
How to use the above command in vbscript??? I am installing a msi using vbscript and want to change the installation path??? Is there any way to use this command in vbscript???
Left by Twikle on Oct 14, 2011 1:37 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
What if neither of TARGETDIR or INSTALLDIR is working?
Eg: I'm trying to install SolidViewLite 2012. If i open the exe i can get the msi file from the %temp% folder. Now if use the command
msiexec /i file.msi /q TARGETDIR=c:\programs\solid

It doesnot work :(
Left by Nitish Mahajan on May 08, 2012 7:40 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
When you say it does not work, what happens? Do you get any errors?
Left by Arthur on May 17, 2012 7:19 PM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
It works for me.
It doesn't work if you have already installed the application in another path.
Uninstall the application and then try:

msiexec /passive TARGETDIR="C:\MyTagretDirectory" /i MyProject.msi
Left by jo on Mar 01, 2013 1:05 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
Its working fine.
But if I want to install the same exe in 2 different paths? How it can be achieved?
Left by Maha on Oct 29, 2013 6:34 PM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
Getting windows installer prompt on using comamnd "
msiexec /passive TARGETDIR="C:\MyTagretDirectory" /i MyProject.msi" and it did not work
Left by AQJ on Jan 30, 2014 12:03 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
AQJ: make sure the target directory exists and writable, and that the installer file name is correct.

When you say did not work, did you get any error messages?
Left by Arthur on Feb 03, 2014 4:54 PM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
msiexec /passive TARGETDIR="C:\MyTagretDirectory" /i MyProject.msi is not copying to the specified Target directory. I tried InstallDIR also, neither worked. Tested on both Windoes XP and Windows 7.
Left by Vinni on Mar 31, 2014 4:06 PM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
Hi Vinni,

Please make sure the following is true:

1) The target and source paths exist;

2) You have sufficient privileges

Also please let us know if you get an error executing this command.

I also have a trick: use the ProcessExplorer app and see at that step the process fails.
Left by Arthur on Jun 29, 2014 5:35 PM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
If the .msi was created from a Visual Studio 'Setup and Deployment' project, it's likely that the appropriate property to set is APPDIR rather than TARGETDIR or INSTALLDIR.
Left by Doctor Bonzo on Jul 01, 2014 8:36 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
I'd like to chime in for anyone in the same situation, because I was not able to use TARGETDIR to set the installation directory from the command line. INSTALLFOLDER worked instead. I built the MSI with WiX 3.9.

The full command was:

msiexec /i sample_installer.msi INSTALLFOLDER="C:\Program Files (x86)\sample\path"

It might be relevant that the directory structure in my WiX source was defined like so:

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="Company" Name="$(var.Manufacturer)">
<Directory Id="INSTALLFOLDER" Name="$(var.ProductName)" />
</Directory>
</Directory>
</Directory>

Though I don't get why TARGETDIR wouldn'd do anything while INSTALLDIR overwrote the directory structure in its entirety...
Left by Valdimar on Mar 20, 2015 2:20 AM

# re: Forcing MSI Installation Into a Specific Directory
Requesting Gravatar...
That script worked as promised! Nothing like a gift that keeps on giving! Thank you.
Left by WILLIAM H DAVIS on Apr 05, 2016 3:15 PM

Your comment:
 (will show your gravatar)


Copyright © Compudicted | Powered by: GeeksWithBlogs.net