简体   繁体   English

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

[英]modify Windows Firewall with command prompt

using Command Prompt to modify Windows Firewall 使用命令提示符修改Windows防火墙

can i allow Domain/Public/Private checkmarks all in the same row (like i can do by manually clicking)? 我可以在同一行中全部允许“域/公共/私人”复选标记吗(就像我可以通过手动单击来完成)?

what i have so far makes 3 entries, one checkmark for each type: 到目前为止,我有3个条目,每种类型都有一个选中标记:

netsh advfirewall firewall add rule name="MyApp" dir=in action=allow program="C:\\MyApp.exe" enable=yes profile=domain netsh advfirewall防火墙添加规则名称=“ MyApp” dir =实际=允许程序=“ C:\\ MyApp.exe” enable =是配置文件=域

netsh advfirewall firewall add rule name="MyApp" dir=in action=allow program="C:\\MyApp.exe" enable=yes profile=public netsh advfirewall防火墙添加规则名称=“ MyApp” dir =实际=允许程序=“ C:\\ MyApp.exe” enable =是配置文件=公共

netsh advfirewall firewall add rule name="MyApp" dir=in action=allow program="C:\\MyApp.exe" enable=yes profile=private netsh advfirewall防火墙添加规则名称=“ MyApp” dir =正在执行=允许程序=“ C:\\ MyApp.exe” enable = yes配置文件=私有

Try this: 尝试这个:

@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

If you want to run it in batch file, just double the %'s for %a to %%a. 如果要在批处理文件中运行它,只需将%a的%s翻倍到%% a。 Remove the Echo when you test for acceptable output. 测试可接受的输出时,请删除回声。

And just to tidy things up a bit: 只是为了整理一下:

@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
)

Here's what you can do to solve it: 解决问题的方法如下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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