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.
- Intermediate
- Windows VPS
- 5 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 12230 (
203.0.113.10:12230). Keep it open while you test. - PowerShell opened as Administrator.
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 the Dashboard 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:
Get-NetTCPConnection -State Listen |
Select-Object LocalAddress, LocalPort, OwningProcess,
@{n='Process';e={(Get-Process -Id $_.OwningProcess).Path}} |
Sort-Object LocalPortThen list established outbound connections:
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:
New-NetFirewallRule -DisplayName "Block ContosoSync outbound" `
-Direction Outbound `
-Program "C:\Program Files\Contoso\sync.exe" `
-Action Block -Profile AnyTo stop a program from accepting inbound connections (a listener):
New-NetFirewallRule -DisplayName "Block devserver inbound" `
-Direction Inbound `
-Program "C:\Tools\devserver.exe" `
-Action Block -Profile AnyBlock 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:
New-NetFirewallRule -DisplayName "Block ContosoSync outbound" `
-Group "RunRacks app blocks" `
-Direction Outbound `
-Program "C:\Program Files\Contoso\sync.exe" `
-Action Block -Profile AnyThe same rule with the older netsh syntax:
netsh advfirewall firewall add rule name="Block ContosoSync outbound" dir=out program="C:\Program Files\Contoso\sync.exe" action=block enable=yes profile=anyIf 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:
Set-NetFirewallProfile -Profile Any -DefaultOutboundAction Block
New-NetFirewallRule -DisplayName "Allow ContosoSync outbound" `
-Direction Outbound `
-Program "C:\Program Files\Contoso\sync.exe" `
-Action Allow -Profile AnyDefault-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:
Set-NetFirewallProfile -Profile Any -DefaultOutboundAction AllowBlock 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:
New-NetFirewallRule -DisplayName "Block LegacyAgent outbound" `
-Direction Outbound `
-Service "LegacyAgent" `
-Action Block -Profile AnyFind the short name with:
Get-Service | Where-Object DisplayName -like "*Legacy*" |
Select-Object Name, DisplayName, StatusNever 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:
Get-NetFirewallRule -DisplayName "Block ContosoSync outbound" |
Get-NetFirewallApplicationFilterTest connectivity from the server:
Test-NetConnection -ComputerName 203.0.113.10 -Port 443Turn on firewall logging so you can see drops:
Set-NetFirewallProfile -Profile Any -LogBlocked True `
-LogFileName "%systemroot%\system32\LogFiles\Firewall\pfirewall.log"
Get-Content "$env:systemroot\system32\LogFiles\Firewall\pfirewall.log" -Tail 40Look for DROP lines that match the ports the application uses. Then confirm your RDP session still works on TCP 12230 — 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>).Pathand recreate the rule with the real path. - RDP disconnects after adding a rule. You blocked a system process or the inbound rule for TCP 12230. Reconnect through the browser console in the Dashboard, 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-NetConnectionProfileand either use-Profile Anyor 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
-Serviceinstead 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 Allowand rebuild the rules more carefully.
Next steps
- Verify the Remote Desktop listener with Check the Windows Firewall rule for RDP port 12230.
- Tighten remote access in Secure Remote Desktop on Windows Server.
- Roll firewall rules out across the domain with Advanced Windows Server: Implementing Group Policy Objects (GPO) for security.
- Pair network rules with host protection in Microsoft Defender basics on Windows Server.
- Review the plans at Windows VPS hosting if you need a larger instance for testing.
Was this guide helpful?
Still stuck?
Ask RunRacks AI for a quick answer, or open a ticket and our team will take a look at your server.
Related guides
Security
Check the Windows Firewall rule for RDP port 12230
Find and verify the inbound TCP 12230 rule that lets Remote Desktop reach your RunRacks server, recreate it if it was deleted and scope it without locking yourself out.
- Intermediate
- Windows VPS · Admin RDP
- 5 min read
Security
Linux Security: Using aide for File Integrity Monitoring on VPS
AIDE builds a checksum database of your system files and reports anything that changed. This guide installs it, creates a baseline, tunes the rules and schedules daily checks on a Linux VPS.
- Advanced
- Linux VPS
- 6 min read
Security
iptables basics: list, allow, drop and save rules
Learn how iptables chains and rule order work, then build a small ruleset that allows SSH and web traffic, drops everything else and can be edited by line number.
- Intermediate
- Linux VPS
- 6 min read