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!