使用防火墙扩展程序在Wix安装程序中添加防火墙例外的问题

4

我是Wix安装程序的新手。我正在尝试为我的程序添加防火墙例外。

我的代码如下:

<Component Id="_VIEW.EXE" Guid="*" Transitive="yes">
     <File Id="view.exe"
           Name="view.exe"
           KeyPath="yes"
           Source="$(var.INSTALLSOURCE)\view.exe">
       <fire:FirewallException Id="view_firewall_domain_tcp"
                               Name="View"
                               Protocol="tcp"
                               Scope="any"
                               IgnoreFailure="yes"
                               Profile="domain" />
       <fire:FirewallException Id="view_firewall_domain_udp"
                               Name="View"
                               Protocol="udp"
                               Scope="any"
                               IgnoreFailure="yes"
                               Profile="domain" />
       <fire:FirewallException Id="view_firewall_private_tcp"
                               Name="View"
                               Protocol="tcp"
                               Scope="any"
                               IgnoreFailure="yes"
                               Profile="private" />
       <fire:FirewallException Id="view_firewall_private_udp"
                               Name="View"
                               Protocol="udp"
                               Scope="any"
                               IgnoreFailure="yes"
                               Profile="private" />
     </File>
  </Component>

在我的代码中,我添加了4个防火墙例外,每个例外的"配置文件(Profile)"和"协议(Protocol)"属性都有不同的值。我的期望结果是创建4个例外。
NAME  GROUP   Profile   Enabled  Action  Override  Program           Local Address   Remote Address   Protocol   Local Port   Remote Port   Allowed Users  Allowed Computers
view          Domain     Yes     Allow    No       c:\test\view.exe    Any               Any            TCP         Any         Any             Any            Any
view          Domain     Yes     Allow    No       c:\test\view.exe    Any               Any            UDP         Any         Any             Any            Any
view          Private    Yes     Allow    No       c:\test\view.exe    Any               Any            TCP         Any         Any             Any            Any
view          Private    Yes     Allow    No       c:\test\view.exe    Any               Any            UDP         Any         Any             Any            Any

但实际结果只创建了一个异常,并且“Protocol”属性的值为“any”,而不是“TCP”或“UDP”:

NAME  GROUP   Profile   Enabled  Action  Override  Program           Local Address   Remote Address   Protocol   Local Port   Remote Port   Allowed Users  Allowed Computers
view          Domain     Yes     Allow    No       c:\test\view.exe    Any               Any            Any         Any         Any             Any            Any

所以,我有两个问题:

  1. 为什么只创建一个异常?异常的名称必须唯一吗?
  2. 为什么“Protocol”属性的值没有生效?

我参考了一个关于防火墙扩展的官方文档: http://wixtoolset.org/documentation/manual/v3/xsd/firewall/firewallexception.html 在这个文档中,我看到了一些关于“File”属性的描述:

文件标识符,用于授予对所有传入端口和协议的访问权限。如果使用File,则不能使用Program。 如果在同一FirewallException元素中同时使用File、Port或Protocol,则该异常将无法在Windows XP和Windows Server 2003上安装。可以使用IgnoreFailure="yes"来忽略结果失败,但是该异常将不会被添加。

这是否意味着,如果我为一个程序设置防火墙规则,即使我设置了“Protocol”,“Protocol”和“Port”属性也会自动变成“Any”?

2个回答

3
现有的wix FirewallException自定义操作使用XP/Server2003 Windows防火墙API。在该API中,为特定可执行文件设置防火墙例外意味着所有端口和所有协议都将对该例外开放。
供参考,XP/Server2003防火墙API接口。请注意,INetFwOpenPort具有获取/设置端口的能力,而INetFwAuthorizedApplication没有。
如果您想在程序上创建防火墙例外并明确限制端口、协议和域,您需要使用随Vista一起提供的Windows“高级”防火墙API。查看这些参考资料: 高级概述
参考指南
命令行参考指南
很遗憾,目前还没有人为wix实现了AdvancedFirewallException扩展来利用这些更新的API。也许我会发起一个众筹活动,看是否有兴趣资助开发;P

2

尝试为每个防火墙例外ID使用不同的名称。这对我有用:

<File Id="sample.exe"
              Name="sample.exe"
              Source="..\TestFrame\bin\debug\sample.exe"
              Vital="yes"
              KeyPath='yes'>

          <fire:FirewallException Id="FirewallDomainSampleTcp"
                                  Name="Domain Sample TCP"
                                  Protocol="tcp"
                                  Port="8080"
                                  Scope="any"
                                  IgnoreFailure="yes"
                                  Profile="domain" />

          <fire:FirewallException Id="FirewallDomainSampleUdp"
                                  Name="Domain Sample UDP"
                                  Protocol="udp"
                                  Port="8080"
                                  Scope="any"
                                  IgnoreFailure="yes"
                                  Profile="domain" />

          <fire:FirewallException Id="FirewallPrivatSampleTcp"
                                  Name="Private Sample TCP"
                                  Protocol="tcp"
                                  Port="8080"
                                  Scope="any"
                                  IgnoreFailure="yes"
                                  Profile="private" />

          <fire:FirewallException Id="FirewallPrivateSampleUdp"
                                  Name="Private Sample UDP"
                                  Protocol="udp"
                                  Port="8080"
                                  Scope="any"
                                  IgnoreFailure="yes"
                                  Profile="private" />
        </File>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接