How can I silently install an MSI package using msiexec installer with a list of options

风流意气都作罢 提交于 2019-12-11 14:59:41

问题


I am trying to install an MSI package with around 10 options. I was hoping to create these options in a .txt file and pass those through to msiexec.exe during the install via the command line using a script such as this:

   C:\Windows\System32\msiexec.exe /qn /i "C:\folder\Installer.msi" /L*V "C:\folder\Installerlog.txt" /t "C:\folder\Installer.switch.txt"

My installer.switch.txt file has a structure similar to this:

Option1=option1 ^
Option1=option2 ^
Option1=option3 ^

With this I hope to pass the options via the installer.switch.txt file. Could you please advise on firstly if this is possible and secondly which errors I might be making in the syntax.

Thanks


回答1:


I have never seen the switch /t used with msiexec.exe - is this your own invention to indicate "text file with switches"? There are built-in ways to set installation parameters and settings that don't rely on text files.

Essentially you can set public properties used inside the MSI via the command line OR you can use a transform (which I find better). A transform is a partial database file - an MSI fragment - which is applied to change the original MSI at install time to customize anything you like in the MSI file.

In other words, I would use a transform to set these options and then apply it via msiexec.exe as described here in the top sections: How to make better use of MSI files. The linked answer is quite long, just look for the sections on public properties and transform with the numbers 1 and 2 in front of each option.


On a technical note: I would add any properties you want to use for your customizations to the SecureCustomProperties list to ensure they can be passed to the deferred mode server installation process.

This is quite technical, but may be important in fringe cases. It involves technicalities with regards to users installing with elevated rights (not admin rights). Just add all customized properties to the SecureCustomProperties list set in the MSI's property table. Your SecureCustomProperties list would read something like: PROP1;PROP2;PROP3 etc... You set this in your transform.




回答2:


Its possible.

I have achieved this through .ini file. On silent installation we can get the ini file path and read the values using key.

Ini file is simple text files with a basic structure.

We can have n number of options in .ini file.

msiexec.exe /i "C:\folder\Installer.msi" /L*V "C:\folder\Installerlog.txt"  /qb  ConfigDirectory=C:\folder\Installer.switch.ini

Run the above command on cmd to install.

Below code is used to read and set the .ini file values.

 public string IniReadValue(string Key, string Section = null)
        {
            StringBuilder temp = new StringBuilder(255);
            int i = GetPrivateProfileString(Section, Key, "", temp,
                                            255, this.path);
            return temp.ToString();
    }

 var MyIni = new IniFileRead("ConfigDirectory");
        var importDir = MyIni.IniReadValue("Option1", "OptionDirectory");
        var exporttDir = MyIni.IniReadValue("Option2", "OptionDirectory");

Installer.switch.ini

[OptionDirectory]
Option1=value1
Option2=value2

Hope it helps.



来源:https://stackoverflow.com/questions/49170763/how-can-i-silently-install-an-msi-package-using-msiexec-installer-with-a-list-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!