简体   繁体   中英

WiX Custom Action to check firewall status causes installer to fail

I have implemented a WiX Custom Action in C# to check whether the Windows firewall is on or off.

I tested the code with a C# console application and it worked without problems.

However, when I use the code in a WiX Custom Action it causes the installer to fail at run-time, with the following error in the msiexec error log:

DEBUG: Error 2755: Server returned unexpected error 1622 attempting to nstall package MyInstaller.msi. The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2755. The arguments are: 1622, MyInstaller.msi,

Action ended 11:26:30: ExecuteAction. Return value 3. Action 11:26:30: FatalError. Action start 11:26:30: FatalError. Action 11:26:30: FatalError. Dialog created Action ended 11:26:31: FatalError. Return value 2. Action ended 11:26:31: INSTALL. Return value 3.

Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", true);

INetFwMgr fwMgr = Activator.CreateInstance(NetFwMgrType) as INetFwMgr;

bool Firewallenabled = fwMgr.LocalPolicy.CurrentProfile.FirewallEnabled;

MessageBox.Show("Firewall enabled: " + Firewallenabled.ToString());

In my WiX XML file the CA is like this:

  <CustomAction Id="CheckWindowsFirewallId"
  BinaryKey="CustomActions.dll"
  DllEntry="CheckWindowsFirewall"  Execute="deferred"  Impersonate="no" Return="check"/>


<InstallExecuteSequence>
<Custom Action="CheckWindowsFirewallId" After="InstallInitialize">NOT Installed</Custom>

I am using Visual Studio 2005, Windows XP, WiX version 3.6.1321.0

I am logged in as admininstrator.

I know exactly which line causes in the problem.

If I comment out the line with "Activator.CreateInstance(NetFwMgrType)" the error does not occur.

I have tried several different combinations of 'deferred' and 'impersonate' with no success.

If I can't get it to work I will try the WiX Firewall Extension instead, but it would be great if someone has an idea why it doesn't work.

There isn't enough information to know for sure. However, my magic eight ball guesses that the assembly your trying to activate a class out of isn't available. The best thing would be to get a debugger on the code and look at the exception. If you're having trouble doing that, catching the exception and writing it to the log file might be useful as well.

I also agree with Yan's comment above. I'd recommend using the built in support for Firewalls in WiX instead of writing your own code if possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM