eddyuk
eddyuk

Reputation: 4190

Passing arguments to msi

In chocolatey documentation they state that in order to pass parameters to MSI need to use following argument:

--ia, --installargs, --installarguments, --install-arguments=VALUE InstallArguments - Install Arguments to pass to the native installer in the package. Defaults to unspecified.

I tried that assuming that it will be automatically appended to MSI execution but parameters were not passed.

Then I looked in chocolateyinstall.ps1 I have, and I noticed silentArgs parameter that has default initialization which looks like exactly arguments that passed to MSI. I tried to remove it with hope it will pass parameters to MSI but still no luck.

So the question is: how do I pass parameters from command line to MSI when using cinst or choco install?

Here is my chocolateyinstall.ps1 which is pretty standard:

$ErrorActionPreference = 'Stop'; # stop on all errors
$toolsDir   = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$packageArgs = @{
  packageName   = $env:ChocolateyPackageName
  unzipLocation = $toolsDir
  fileType      = 'msi'
  file          = Get-Item $toolsDir\*.msi
  checksumType  = 'sha256' #default is md5, can also be sha1, sha256 or sha512
  # MSI
  silentArgs    = "/qn /norestart /l*v `"$($env:TEMP)\$($packageName).$($env:chocolateyPackageVersion).MsiInstall.log`""
  validExitCodes= @(0, 3010, 1641)
}

Install-ChocolateyPackage @packageArgs 

Upvotes: 1

Views: 1954

Answers (1)

Gary Ewan Park
Gary Ewan Park

Reputation: 18981

Let take for example the installation of the Chocolatey GUI package, which also uses an MSI. If you run the following command:

choco install chocolateygui --install-arguments="'/forcerestart'"

This additional argument will be passed to the underlying MSI, which will cause the machine to be rebooted when the installation of the MSI is completed.

NOTE: This will have the side effect of not completing the Chocolatey installation, so the package will not actually be marked as installed. This was just an example of augmenting the parameters passed to the MSI.

Another example would be to run the following:

choco install chocolateygui --install-arguments="'/forcerestart'" --override-arguments

The second parameter, --override-arguments causes only the arguments that are passed in to be respected. Doing this causes the installation to block, since the silent arguments have been removed from the package.

So, long story short, it sounds like what you are doing is exactly correct. If you can share the exact command that you are trying to use, it might help to figure out what is going on.

As a side note, looks like you are creating an embedded Chocolatey Package, meaning that the MSI is actually contained within the nupkg file. This is perfectly valid, however, you should be using Install-ChocolateyInstallPackage (https://chocolatey.org/docs/helpers-install-chocolatey-install-package), rather than Install-ChocolateyPackage (https://chocolatey.org/docs/helpers-install-chocolatey-package)

Upvotes: 2

Related Questions