如何透過命令行為程序建立出站規則?

如何透過命令行為程序建立出站規則?

我想阻止幾個程式存取 Internet。描述了手動(即點擊)解決方案這裡

有沒有辦法透過 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 commandlet,請安裝 NetSecurity 模組:

Install-Module -Name NetSecurity

相關內容