Reputation: 587
I have setup.msi file. I need to run the installation from the command line in silent mode. It is also necessary to specify the path where will this installation. I tried to use TARGETDIR and INSTALLDIR parameters, but the installation going is in the default folder:
msiexec.exe /i c:\setup.msi TARGETDIR="c:\result" /qb
Also if you run this command again, the installation will not happen, because msiexec think that the product is already installed. In this case, I need to get the product installation in the specified directory and the version value in the registry has been updated.
How can I install product in a specific directory regardless of whether the product is installed or not.
Upvotes: 3
Views: 9043
Reputation: 338
I use powershell to check if it's already installed and install it if it's not already.
x86 MSI:
((Get-ItemProperty HKLM:\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Where { $_.DisplayName -like \"*[APPLICATION_NAME]*\" }) -ne $null)
X64 MSI:
((Get-ItemProperty HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Where { $_.DisplayName -like \"*[APPLICATION_NAME]*\" }) -ne $null)
You can take the result and store it in a variable if you want such as $ApplicationInstalled and then condition your installation based on the result.
if (-not $ApplicationInstalled)
{
#MSI Install Commmand
}
Upvotes: 0
Reputation: 3674
Basically, your commandline is not wrong. But, which variable is the correct one, is strongly dependent on the msi package itself, it is not a rule, that TARGETDIR works. At least it works for MSI files following best practices. Normally TARGETDIR is correct, and for InstallShield-builds is INSTALLDIR working best.
But if someone has authored the folder directly as ProgramFilesFolder, then this is fixed. Download Orca or better InstEd or a similar tool and you have to look inside the MSI file.
Your second question: "How can I install product in a specific directory regardless of whether the product is installed or not?"
This is not directly possible. Windows Installer has rules, and these don't allow multiple installation in different directories without further effort: Moreover I am not sure why do you want this:
Here is a bit more knowledge for this:
Normally, everyone who wants to install in another directory, first uninstalls the product. That is standard practice. With commandline parameter /x you can uninstall it. Then install with a new path.
Your are correct, if you install a second time with your (same) command line, nothing will happen or change. Instead of an uninstall a repair (correction) is possible. Use the additional parameters REINSTALL=ALL REINSTALLMODE=vemus for this as a good default. But as said, it is not possible to change installation path with this.
If you really mean this: For having installed multiple "copies" of the same software in different directories, things are a bit tricky with MSI. I recommand professional MSI knowledge for this so maybe you would need paid consult for that. Most people use copy scripts instead of MSI for such things. But when you want to have real multiple setup versions installed, search for MSDN entry "Installing Multiple Instances with Instance Transforms" as a first starting point.
Upvotes: 5