.EXE block in the Windows Firewall with a context menu

I got the following code bit for a .REG file, which adds “Add to Firewall” to the context menu by right-clicking on the .EXE file. It simply creates the Source Rule in the Windows Firewall for this particular file that you selected, instead of doing it manually.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\exefile\shell]

[HKEY_CLASSES_ROOT\exefile\shell\Add To Firewall]

[HKEY_CLASSES_ROOT\exefile\shell\Add To Firewall\command]
@="netsh advfirewall firewall add rule name=\"%1\" dir=out action=block program=\"%1\""

http://oi46.tinypic.com/2rgnxaf.jpg

My problem is that the following syntax name=\"%1\"gives the full directory (C: \ New folder \ test.exe) as the name in the Windows firewall instead of the simple test.exe

Another feature I'm looking for is to add all this to the right-click, and not the usual right-click, because I really don't use this function often, so I see it every time I right-click on the. Exe

PS. To remove it from the context menu, do the following:

Windows Registry Editor Version 5.00


[-HKEY_CLASSES_ROOT\exefile\shell\Add To Firewall]

Hope to hear from someone, and thanks in advance from here;)

+5
source share
1 answer

The following will do exactly what you ask, but this requires that UAC be disabled. Without creating a script file or using third party tools or, alternatively, rewriting a key runas, I don't think you could create a UAC prompt.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\exefile\shell\firewallblock]
@="Add to Firewall"         ; String to be displayed in context menu
"HasLUAShield"=""           ; Adds UAC shield icon to the left of the command
"Extended"=""               ; Requires shift to be held when right-clicking

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

, FOR - , , . %%a ( , x:\fully\qualified\path\filename.exe) %%~nxa, filename.exe %%~na filename.

UAC, , , , :

@="elevate.exe -c for %%a in (\"%1\") do netsh advfirewall firewall add rule name=\"%%~na\" dir=out action=block program=\"%%~nxa\""

, !

+7

All Articles