Skip to content

Instantly share code, notes, and snippets.

@jnaskali
Last active April 22, 2024 04:28
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save jnaskali/5936789 to your computer and use it in GitHub Desktop.
Save jnaskali/5936789 to your computer and use it in GitHub Desktop.
Block/Unblock exe in Windows Firewall using right-click menu (updated thanks to ghjbnm's comment below)
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall]
@=""
"MUIVerb"="Windows Firewall"
"icon"="%SystemRoot%\\system32\\FirewallControlPanel.dll,0"
"subcommands"=""
[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell]
@=""
[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell\block]
@=""
"MUIVerb"="Block"
"icon"="%SystemRoot%\\system32\\FirewallControlPanel.dll,1"
[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell\block\command]
@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -Executionpolicy ByPass -WindowStyle Hidden -NoLogo -Command \"start powershell -Verb runas -ArgumentList \\\"-NoLogo -WindowStyle Hidden -command `\\\"New-NetFirewallRule -DisplayName ([System.IO.Path]::GetFilenameWithoutExtension('%1')) -Name '%1' -Enabled True -Direction Outbound -Action Block -Program '%1'`\\\"\\\"\""
[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell\Remove]
@=""
"MUIVerb"="Allow"
"icon"="%SystemRoot%\\system32\\FirewallControlPanel.dll,2"
[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell\Remove\command]
@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -Executionpolicy ByPass -WindowStyle Hidden -NoLogo -Command \"start powershell -Verb runas -ArgumentList \\\"-NoLogo -WindowStyle Hidden -command `\\\"Remove-NetFirewallRule -Name '%1'`\\\"\\\"\""
@Wolverine1977
Copy link

Can you please explain how to add the block and remove commands to a submenu. e.g. I would like a Context menu called Security Tools and have the block and block remove under that Security Tools menu, also is it possible to assign a custom icon to the commands rather than the UAC shield?
Great Reg Edit - Thanks

@AdKiller
Copy link

this looked like a godsend... but sadly clicking Firewall Unblock does not add anything to the firewall outbound or inbound rules.

OS Windows 10 Pro v1607 64 bit

@krystian3w
Copy link

@Wolverine1977: Try this method to create submenu:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall]
@=""
"MUIVerb"="Windows Firewall"
"icon"="%SystemRoot%\\system32\\FirewallControlPanel.dll,0"
"subcommands"=""

[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell]
@=""


[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell\block]
@=""
"MUIVerb"="Block In Windows Firewall"
"icon"="%SystemRoot%\\system32\\FirewallControlPanel.dll,1"

[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell\block\command]
@="cmd.exe /s /c for %%a in (\"%1\") do netsh advfirewall firewall add rule name=\"Block %%~na\" dir=out action=block program=\"%1\""

[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell\Remove]
@=""
"MUIVerb"="Remove From Windows Firewall"
"icon"="%SystemRoot%\\system32\\FirewallControlPanel.dll,2"

[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell\Remove\command]
@="cmd.exe /s /c for %%a in (\"%1\") do netsh advfirewall firewall delete rule name=\"Block %%~na\""

No Fixed UAC permissions if UAC is enabled. You can try fix with run as / powershell / trid-party software / disable UAC.


@AdKiller:

but sadly clicking Firewall Unblock does not add anything to the firewall (...) rules.

The command delete rule, no change / add new (blocking is more important than allow).

Maybe UAC block remove rule to firewall, I see access is denied. You can try fix with run as / powershell / trid-party software / disable UAC.

@OzzyJoker
Copy link

Thats the one that worked for me

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\exefile\shell\firewallblock]
@="Add to Firewall"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\exefile\shell\firewallblock\command]
@=""C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Executionpolicy ByPass -WindowStyle Hidden -NoLogo -Command "start powershell -Verb runas -ArgumentList \"-NoLogo -WindowStyle Hidden -command \\\"New-NetFirewallRule -DisplayName ([System.IO.Path]::GetFilenameWithoutExtension('%1')) -Name '%1' -Enabled True -Direction Outbound -Action Block -Program '%1'\"\"""

[HKEY_CLASSES_ROOT\exefile\shell\firewallremove]
@="Remove from Firewall"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\exefile\shell\firewallremove\command]
@=""C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Executionpolicy ByPass -WindowStyle Hidden -NoLogo -Command "start powershell -Verb runas -ArgumentList \"-NoLogo -WindowStyle Hidden -command \\\"Remove-NetFirewallRule -Name '%1'\"\"""

@Sopor
Copy link

Sopor commented Dec 19, 2019

It took some time before i manage to get this to work. Many chars are removed because it was not included in three backticks.
Here is a complete and working file. I have added "Extended"="".

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\exefile\shell\firewallblock]

@="Add to Firewall"
"HasLUAShield"=""
"Extended"=""

[HKEY_CLASSES_ROOT\exefile\shell\firewallblock\command]

@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -Executionpolicy ByPass -WindowStyle Hidden -NoLogo -Command \"start powershell -Verb runas -ArgumentList \\\"-NoLogo -WindowStyle Hidden -command `\\\"New-NetFirewallRule -DisplayName ([System.IO.Path]::GetFilenameWithoutExtension('%1')) -Name '%1' -Enabled True -Direction Outbound -Action Block -Program '%1'`\\\"\\\"\""

[HKEY_CLASSES_ROOT\exefile\shell\firewallremove]
@="Remove from Firewall"
"HasLUAShield"=""
"Extended"=""

[HKEY_CLASSES_ROOT\exefile\shell\firewallremove\command]
@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -Executionpolicy ByPass -WindowStyle Hidden -NoLogo -Command \"start powershell -Verb runas -ArgumentList \\\"-NoLogo -WindowStyle Hidden -command `\\\"Remove-NetFirewallRule -Name '%1'`\\\"\\\"\""

Copy link

ghost commented Jun 20, 2020

Following worked for me (Windows 10 Build 1909)

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall]
@=""
"MUIVerb"="Windows Firewall"
"icon"="%SystemRoot%\\system32\\FirewallControlPanel.dll,0"
"subcommands"=""

[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell]
@=""


[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell\block]
@=""
"MUIVerb"="Block"
"icon"="%SystemRoot%\\system32\\FirewallControlPanel.dll,1"

[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell\block\command]
@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -Executionpolicy ByPass -WindowStyle Hidden -NoLogo -Command \"start powershell -Verb runas -ArgumentList \\\"-NoLogo -WindowStyle Hidden -command `\\\"New-NetFirewallRule -DisplayName ([System.IO.Path]::GetFilenameWithoutExtension('%1')) -Name '%1' -Enabled True -Direction Outbound -Action Block -Program '%1'`\\\"\\\"\""

[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell\Remove]
@=""
"MUIVerb"="Allow"
"icon"="%SystemRoot%\\system32\\FirewallControlPanel.dll,2"

[HKEY_CLASSES_ROOT\exefile\shell\WindowsFirewall\Shell\Remove\command]
@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -Executionpolicy ByPass -WindowStyle Hidden -NoLogo -Command \"start powershell -Verb runas -ArgumentList \\\"-NoLogo -WindowStyle Hidden -command `\\\"Remove-NetFirewallRule -Name '%1'`\\\"\\\"\""

@jnaskali
Copy link
Author

Following worked for me (Windows 10 Build 1909)

I updated the gist using your solution. Thanks!

@jpeni
Copy link

jpeni commented Jun 25, 2020

jnaskali
Any chance of including the update DATE in the gist when you change it?

@Owned67
Copy link

Owned67 commented Jan 6, 2024

22h2 it does not work for me...

@tommcg
Copy link

tommcg commented Jan 10, 2024

22h2 it does not work for me...

Same. Not working. I have no clue how to fix it. I tried to tweak it, but no success.

@Owned67
Copy link

Owned67 commented Jan 13, 2024

22h2 it does not work for me...

Same. Not working. I have no clue how to fix it. I tried to tweak it, but no success.

ive found easy context menu, it make this and work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment