如何通过命令行为程序创建出站规则?

如何通过命令行为程序创建出站规则?

我有几个程序想阻止它们访问互联网。本文介绍了一种手动(即点击)解决方案这里

有没有办法通过 Windows 10 上的命令行来完成此操作?

类似这样的伪代码:

firewall --create --outbound --name "myRule" --target "C:\some\program.exe"

它可以是 CMD 或 PowerShell。

答案1

使用 Powershell,尝试以下操作:

New-NetFirewallRule -Direction Outbound -Program “C:\some\program.exe” -Action Block -Profile All -DisplayName “Block My Program.exe” -Description “Block My Program.exe” 

这将阻止所有配置文件:域、私有和公共。如果您只想阻止特定配置文件,请更改-Profile All-Profile Public是否要阻止公共网络或-Profile Domain, Private是否要阻止域和私有网络。

如果您没有 New-NetFirewallRule 命令行程序,请安装 NetSecurity 模块:

Install-Module -Name NetSecurity

相关内容