Programmatically installing MSI packages

后端 未结 6 1768
暖寄归人
暖寄归人 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:43

    There's a COM object that offers an API for the installer:

    First add a reference to COM object "Microsoft Windows Installer Object Library" to your project. Then you can start with the following code:

    using System;
    using WindowsInstaller;
    
    namespace TestApp
    {
        public class InstallerTest
        {
            public static void Install()
            {
                Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");
                Installer installer = (Installer)Activator.CreateInstance(type);
                installer.InstallProduct("YourPackage.msi");
            }
        }
    }
    

    And there's a documentation about the Installer Object.

提交回复
热议问题