Security

Advanced Windows Firewall: Blocking Specific Application Executables

Windows Firewall can filter by executable path, not only by port. This guide shows how to block a specific program inbound and outbound with PowerShell, and how to verify the rule.

IntermediateWindows server5 min read

Windows Firewall can filter traffic by executable path, not just by port. This guide shows you how to block a specific application in Windows Firewall with PowerShell, how to allow only one program outbound, and how to confirm the rule is actually dropping traffic.

Program rules are useful when a port-based rule is too broad. If three services share TCP 443, you cannot block one of them by port. You can block it by executable.

Before you start

You need:

  • A Windows VPS running Windows Server 2019–2025, with Administrator rights.
  • An RDP session on TCP port 3389 (203.0.113.10:3389). Keep it open while you test.
  • PowerShell opened as Administrator.

Warning: A block rule on the wrong executable can cut RDP, DNS, Windows Update or licensing. Add one rule at a time, and keep a second session or the browser console in your VPS provider's control panel open so you can recover if you lock yourself out.

One important detail: Windows Firewall matches the file path, not the file hash. If an application updates into a new folder, the rule stops matching. Re-check paths after major updates.

Find the executable you want to block

Start by identifying the process behind the traffic. List listening ports with their owning process:

PowerShell
Get-NetTCPConnection -State Listen |
  Select-Object LocalAddress, LocalPort, OwningProcess,
    @{n='Process';e={(Get-Process -Id $_.OwningProcess).Path}} |
  Sort-Object LocalPort

Then list established outbound connections:

PowerShell
Get-NetTCPConnection -State Established |
  Select-Object RemoteAddress, RemotePort, OwningProcess,
    @{n='Process';e={(Get-Process -Id $_.OwningProcess).Path}}

Write down the full path, for example C:\Program Files\Contoso\sync.exe. If the Process column is empty, the process runs as SYSTEM inside a service host — see the service section below.

Block an application in Windows Firewall

To stop a program from making outbound connections:

PowerShell
New-NetFirewallRule -DisplayName "Block ContosoSync outbound" `
  -Direction Outbound `
  -Program "C:\Program Files\Contoso\sync.exe" `
  -Action Block -Profile Any

To stop a program from accepting inbound connections (a listener):

PowerShell
New-NetFirewallRule -DisplayName "Block devserver inbound" `
  -Direction Inbound `
  -Program "C:\Tools\devserver.exe" `
  -Action Block -Profile Any

Block rules take precedence over allow rules for the same traffic, so you do not need to remove an existing allow rule first.

Use a group name so you can find your own rules later:

PowerShell
New-NetFirewallRule -DisplayName "Block ContosoSync outbound" `
  -Group "App blocks" `
  -Direction Outbound `
  -Program "C:\Program Files\Contoso\sync.exe" `
  -Action Block -Profile Any

The same rule with the older netsh syntax:

CMD
netsh advfirewall firewall add rule name="Block ContosoSync outbound" dir=out program="C:\Program Files\Contoso\sync.exe" action=block enable=yes profile=any

Tip: If you only want to block one destination, add -RemoteAddress 203.0.113.10 to the rule. That keeps the program working everywhere else.

Allow only one application outbound

A stricter design is default-deny outbound, with allow rules for the programs you trust. Set the outbound default first, then add allow rules:

PowerShell
Set-NetFirewallProfile -Profile Any -DefaultOutboundAction Block

New-NetFirewallRule -DisplayName "Allow ContosoSync outbound" `
  -Direction Outbound `
  -Program "C:\Program Files\Contoso\sync.exe" `
  -Action Allow -Profile Any

Warning: Default-deny outbound will break Windows Update, DNS resolution, time sync and activation until you allow the system processes that handle them. Do not run this over RDP without a console session available. On a remote server, allow by service (next section) rather than by path.

If something breaks, restore the default immediately:

PowerShell
Set-NetFirewallProfile -Profile Any -DefaultOutboundAction Allow

Block by service instead of by path

Many Windows components share svchost.exe, so a path rule cannot separate them. Use the service short name instead:

PowerShell
New-NetFirewallRule -DisplayName "Block LegacyAgent outbound" `
  -Direction Outbound `
  -Service "LegacyAgent" `
  -Action Block -Profile Any

Find the short name with:

PowerShell
Get-Service | Where-Object DisplayName -like "*Legacy*" |
  Select-Object Name, DisplayName, Status

Warning: Never block svchost.exe by path. It hosts RPC, DNS, DHCP, Windows Update and other core services, and blocking it can make the server unreachable.

Check it works

Confirm the rule exists and points at the right file:

PowerShell
Get-NetFirewallRule -DisplayName "Block ContosoSync outbound" |
  Get-NetFirewallApplicationFilter

Test connectivity from the server:

PowerShell
Test-NetConnection -ComputerName 203.0.113.10 -Port 443

Turn on firewall logging so you can see drops:

PowerShell
Set-NetFirewallProfile -Profile Any -LogBlocked True `
  -LogFileName "%systemroot%\system32\LogFiles\Firewall\pfirewall.log"

Get-Content "$env:systemroot\system32\LogFiles\Firewall\pfirewall.log" -Tail 40

Look for DROP lines that match the ports the application uses. Then confirm your RDP session still works on TCP 3389 — if it does, the rule did not touch the Remote Desktop listener.

Troubleshooting

  • The application still connects. The rule path does not match the running executable. Updates often move binaries, and some apps run a copy from %LOCALAPPDATA%. Check (Get-Process -Id <pid>).Path and recreate the rule with the real path.
  • RDP disconnects after adding a rule. You blocked a system process or the inbound rule for TCP 3389. Reconnect through the browser console in your VPS provider's control panel, then remove the rule with Remove-NetFirewallRule -DisplayName "Block ContosoSync outbound".
  • The rule exists but nothing is blocked. The connection is on a network profile you did not include. Check Get-NetConnectionProfile and either use -Profile Any or add the missing profile.
  • A service still talks to the internet. The traffic comes from a different service, or from a shared host process. Block by -Service instead of by path, or block the remote port.
  • Windows Update, DNS or time sync fails. Default-deny outbound is too strict. Run Set-NetFirewallProfile -Profile Any -DefaultOutboundAction Allow and rebuild the rules more carefully.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.