首页 文章

如何添加出站Windows防火墙例外?

提问于
浏览
14

我需要为我正在编写的应用程序打开 outbound 连接的Windows防火墙 .

我能找到的最佳答案在这里:

http://www.shafqatahmed.com/2008/01/controlling-win.html

http://www.vincenzo.net/isxkb/index.php?title=Adding_a_rule_to_the_Windows_firewall

问题是该方法仅创建 inbound 规则,而不是 outbound 规则 . (C#和InnoSetup脚本都使用相同的方法 . )这对我来说完全没用 .

Windows防火墙的默认行为是允许出站流量,但这并不能保证有人不会更改它 .

我宁愿在安装程序(使用InnoSetup)中执行此操作,而不是在C#中执行此操作 .

我错过了什么?

有谁知道如何创建 outbound 规则?

4 回答

  • 1

    netsh 的问题在于它在某些Windows版本(例如Windows Vista Basic)上不起作用 . 这就是为什么不使用 netsh 添加异常更好的原因 . This article contains sample Inno Setup code .

  • 23

    如果需要为应用程序添加一些例外,可以使用 netsh .

    在命令行中写入(对于XP):

    netsh firewall add allowedprogram ?
    

    在命令行中写入(对于W7):

    netsh advfirewall firewall add rule ?
    

    这种差异因为 netsh firewall 命令已被弃用 . 相反,我们必须使用命令 netsh advfirewall firewall .

    有关使用命令netsh advfirewall firewall而不是netsh firewall命令的更多信息,我们可以在知识库中看到:http://go.microsoft.com/fwlink/?linkid=121488

    例子:

    为messenger.exe添加没有安全封装的传入流量规则:

    netsh advfirewall firewall add rule name="allow messenger" dir=in program="c:\programfiles\messenger\msmsgs.exe" security=authnoencap action=allow
    

    在端口80上为传出流量添加规则:

    netsh advfirewall firewall add rule name="allow80" protocol=TCP dir=out localport=80 action=block
    

    通过端口80为TCP提供安全和流量加密的入站流量规则:

    netsh advfirewall firewall add rule name="Require Encryption for Inbound TCP/80" protocol=TCP dir=in localport=80 security=authdynenc action=allow
    
  • 1

    TechNet:Create an Outbound Port Rule on Windows 7, Windows Vista, Windows Server 2008 or Windows Server 2008 R2

    虽然我假设您打算以编程方式创建此类规则,但如果是这种情况,您可能会对Working with Group Policy Objects Programmatically感兴趣 .

    最后,如果您计划在安装期间执行此操作,InnoSetup应该能够在设置时合并必要的注册表项 .

  • 0

    这是可以传递给Windows命令行工具的众多任务之一 . netsh做了适当的事情,但它(就像netsh所做的一切)几乎是不可能找到的 . 简单的版本是:
    netsh firewall add allowedprogram <path> <name>
    有关详细信息,请运行:
    netsh firewall add allowedprogram ?

    这些可以在 [Run] 部分中完成,也可以通过调用 Exec 来完成 .

    请注意,这在Windows 7中已经过折旧;如果您只定位Vista / 2008或更高版本,则应使用 netsh advfirewall firewall . 微软有an article从前者转换后者,但我仍然需要支持XP,所以我没有这样做 .

相关问题