Block .EXE in Windows Firewall with context menu

微笑、不失礼 提交于 2019-12-05 13:31:43

The following will do exactly what you're asking, but it requires that you have UAC disabled. Without creating a script file or using third party tools, or alternatively overwriting the runas key, I don't think you would be able to 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\""

To elaborate, I use the FOR command not because of its looping functionality but because it gives me access to parameter extensions. I modify %%a (which we'll say has a value of x:\fully\qualified\path\filename.exe) with %%~nxa to use filename.exe and %%~na to use filename.

As for the UAC stuff, I'd just use one of those third party tools I mentioned above and change the command accordingly, e.g.:

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

Hope it helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!