Detect silent install in .NET Custom Action

2019-02-14 03:28发布

How do you detect that the install is running in silent mode?

I have a custom application that I've added a .msi setup project. I run the .msi file with the /qb switch, and in my custom installer c# code I would like to be able to detect this.

Edit: nobugs says to test the UILevel property. How do I access the UILevel property from a class derived from the System.Configuration.Install.Installer class?

2条回答
The star\"
2楼-- · 2019-02-14 04:10

First I would point out that InstallUtil is a very bad pattern. They run out of process, tatoo the process with a CLR version and when they fail they raise a 1001 error modal dialog even during a silent install.

Instead you should use WiX's DTF pattern.

MsiGetMode ( Session.Mode ) is limited during deferred execution so you will have to serialize and deserialize the UILevel.

http://www.msifaq.com/a/1044.htm

查看更多
干净又极端
3楼-- · 2019-02-14 04:14

Taking the hint from nobugz, I did the following:

  1. On the Custom Actions view of the .msi setup project, I added the following to my CustomActionData (to pass the UILevel through to my custom installer):

    /UILevel="[UILevel]"

  2. Within my C# code for the code derived from base class Installer, I added code to get the value:

    string uiLevelString = Context.Parameters["UILevel"];

  3. It was then simple to parse the string for an int value. If the value is <= 3, it is a silent install.

查看更多
登录 后发表回答