Programmatically installing MSI packages

后端 未结 6 1769
暖寄归人
暖寄归人 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条回答
  •  猫巷女王i
    2020-12-03 08:56

    The basic Win32 API (that can be pinvoked if necessary) is MsiInstallProduct. This is where practically all other mentioned APIs and calls will end up.

    https://msdn.microsoft.com/en-us/library/aa370315(v=vs.85).aspx

    Just pass the full path to the MSI file and your command line (including quiet options etc) and check the result to see if it installed correctly.

    Note that there is a simple p/invoke declaration for managed code:

    [DllImport("msi.dll", CharSet = CharSet.Auto, SetLastError=true)]

    static extern UInt32 MsiInstallProduct(string packagePath, string commandLine);

提交回复
热议问题