Technical Anshu
Tutorials Blog
⌨️ Command Line

Block a Program from the Internet Using Command Line netsh

The GUI wizard works, but a technician fixing ten PCs does not click through seven screens ten times. One netsh command creates the same block rule — and it can be pasted into a script or run in seconds.

✍️ Technical Anshu🪟 Windows 10 / 11⏱️ 1 minute per rule
🎥 Prefer watching first? The video shows the GUI method this command replaces

Everything the firewall wizard does can be done from an administrator Command Prompt with netsh advfirewall. The command below creates the same outbound block rule as the GUI method — same effect, no clicking. Every command here is written exactly as you should type it: copy, paste, change the name and path, Enter.

Administrator: Command Prompt
netsh advfirewall firewall add rule name="Block MyApp" dir=out program="C:\Program Files\MyApp\MyApp.exe" action=block profile=any Ok.
The add rule command and its answer — a plain Ok. means the rule was created.
1

Open an Administrator Command Prompt

Firewall commands are refused without elevation, so this step is not optional:

  1. Click Start and type cmd
  2. Right-click Command Prompt → Run as administrator
  3. Click Yes on the UAC prompt — the title bar should now say Administrator: Command Prompt
2

Create the Block Rule with One Command

Paste this command, changing only the rule name and the program path:

netsh advfirewall firewall add rule name="Block MyApp" dir=out program="C:\Program Files\MyApp\MyApp.exe" action=block profile=any

  1. dir=out — the rule controls connections the program starts (outbound)
  2. action=block — drop that traffic instead of allowing it
  3. profile=any — the block applies on Domain, Private and Public networks alike
  4. Keep the quotes around the name and the path — paths contain spaces, and without quotes the command fails

The answer is a single word: Ok. The rule is live immediately.

3

Verify the Rule Was Created Correctly

Check the rule before you trust it:

netsh advfirewall firewall show rule name="Block MyApp"

The output lists the rule's direction, program path, profiles and action. Confirm Enabled: Yes, Direction: Out, Action: Block and that the program path is exactly right — a typo in the path creates a rule that silently blocks nothing.

4

The PowerShell Equivalent and Deleting the Rule

Microsoft now recommends the PowerShell NetSecurity commands for new scripts. The same rule in PowerShell (run as administrator) is:

New-NetFirewallRule -DisplayName "Block MyApp" -Direction Outbound -Program "C:\Program Files\MyApp\MyApp.exe" -Action Block

To remove the netsh rule later, one command does it:

netsh advfirewall firewall delete rule name="Block MyApp"

Be careful: delete works by name, so if two rules share the same name, both are deleted. Give every rule a unique name.

5

Save Your Commands as a Ready-Made Script

If you set up the same blocks on many PCs — a classroom, an office, a family fleet — paste your add rule commands, one per line, into Notepad and save the file as block-apps.bat. Right-click it → Run as administrator on each machine and every rule is created in one pass. Keep the names in the script identical to the names in your delete commands, and removing the whole set later is the same trick in reverse.

🔴 netsh still works. Microsoft has marked parts of netsh as legacy and points admins to PowerShell, but netsh advfirewall commands still work fully in Windows 10 and 11 — and both methods create the very same rule.

🎥 Watch the Complete Video

Watch the video for the visual version — same rule, created with mouse clicks, so you can compare both methods.

▶️ Watch Full Video
❓ Common Questions (FAQ)

The command says the requested operation requires elevation. What now?

You are in a normal Command Prompt. Close it and reopen with Run as administrator — firewall changes always need an administrator window.

Can I block inbound traffic with netsh too?

Yes — change dir=out to dir=in. For stopping an app from reaching the internet, outbound is the rule that matters; inbound rules control connections that other computers start towards you.

Do I need to restart the PC after adding the rule?

No. Firewall rules apply the moment they are created. Just restart the app itself so it makes fresh connection attempts.

This guide is based on the Technical Anshu video Block Internet Access for Any Application in Seconds • Stuck on any step? Ask in the video comments — you will get a reply there 🙏