使用命令提示符修改Windows防火墙

时间:2015-02-19 18:12:31

标签: batch-file windows-firewall

使用命令提示符修改Windows防火墙

我可以允许同一行中的域/公共/私人复选标记(就像我可以手动点击一样)吗?

我到目前为止有3个条目,每种类型都有一个复选标记:

  

netsh advfirewall防火墙添加规则名称=“MyApp”dir = in action = allow program =“C:\ MyApp.exe”enable = yes profile = domain

     

netsh advfirewall防火墙添加规则名称=“MyApp”dir = in action = allow program =“C:\ MyApp.exe”enable = yes profile = public

     

netsh advfirewall防火墙添加规则名称=“MyApp”dir = in action = allow program =“C:\ MyApp.exe”enable = yes profile = private

2 个答案:

答案 0 :(得分:2)

试试这个:

@echo off
setlocal

set "fcmd=netsh advfirewall firewall add rule name="MyApp" dir=in action=allow program="C:\MyApp.exe" enable=yes profile="
for %a in (domain public private) do (
    echo %fcmd%%a

如果你想在批处理文件中运行它,只需将%a的%&加倍到%% a。 在测试可接受的输出时删除Echo。

只是为了整理一下:

@echo off
setlocal

set fcmd=netsh advfirewall firewall add rule ^
 name="MyApp" dir=in action=allow program="C:\MyApp.exe" ^
 enable=yes profile=
for %a in (domain public private) do (
    echo %fcmd%%a
)

答案 1 :(得分:2)

以下是解决问题的方法:

profile=Private and/or public and/or domain
(To add rule in more than one profile use “,” E.g.: profile=private, domain )