Programmatically installing MSI packages

后端 未结 6 1742
暖寄归人
暖寄归人 2020-12-03 08:23

I would like to install a given .msi package programmatically from my C# .NET application, preferably with the installation parameters that my application specifies (like th

6条回答
  •  攒了一身酷
    2020-12-03 08:50

    There are two approaches to solving your problem.

    The first one as mentioned by @Glytzhkof is to use the Microsoft.Deployment.WindowsInstaller .NET wrapper API. This is some seriously powerful stuff but requires some time to get familiar with. You can get the latest version here (UPDATE: Stein Åsmul 28.12.2018: DTF is now part of the WiX toolkit).

    The other approach is to use Transforms (.MST files). Transform files can be generated using Microsoft Orca or InstallShiled. The MSTs contains all the customizations that you need and can be applied on the MSI using this command line:

    msiexec /i somemsi.msi TRANSFORMS=somemst.mst /qb
    

    Additionally you can pass parameters directly in the command line:

    msiexec /i  /qb AGREETOLICENSE=YES INSTALLDIR=C:\Temp
    etc...
    

    However, you will need to edit the MSI in an ORCA/InstallShield to determine which parameters are actually used.

    The parameters used in the above example are not universal.

    The actual installation can be complicated because of the presence of custom actions etc. In fact there is a whole industry that is built around msi customizations. Its called Applications Repackaging.

提交回复
热议问题