There is a Context Menu
that I have assigned to the right mouse button as Windows Firewall
. And I am using the following code to delete a security rule.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Windows Firewall]
@=""
"MUIVerb"="Windows Firewall"
"icon"="%SystemRoot%\\system32\\FirewallControlPanel.dll,0"
"subcommands"=""
[HKEY_CLASSES_ROOT\*\shell\Windows Firewall\shell\Delete Rule (Outgoing)]
@=""
MUIVerb"="Delete Rule (Outgoing)"
"Icon"="%SystemRoot%\\system32\\FirewallControlPanel.dll,2"
[HKEY_CLASSES_ROOT\*\shell\Windows Firewall\shell\Delete Rule (Outgoing)\command]
@="powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -NoProfile -Command Start-Process -Verb RunAs powershell.exe '-NoExit -ExecutionPolicy Bypass -NoProfile -Command netsh advfirewall firewall delete rule name=$([IO.Path]::GetFileNameWithoutExtension(\\\\\\\"%1\\\\\\\")) program=\\\\\\\"%1\\\\\\\" dir=out'"
And likewise I want it to re-add this code as "action=allow"
with a single script after deleting.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Windows Firewall]
@=""
"MUIVerb"="Windows Firewall"
"icon"="%SystemRoot%\\system32\\FirewallControlPanel.dll,0"
"subcommands"=""
[HKEY_CLASSES_ROOT\*\shell\Windows Firewall\shell\Allow (Out)]
@=""
MUIVerb"="Allow (Out)"
"Icon"="%SystemRoot%\\system32\\FirewallControlPanel.dll,2"
[HKEY_CLASSES_ROOT\*\shell\Windows Firewall\shell\Allow (Out)\command]
@="powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -NoProfile -Command Start-Process -Verb RunAs powershell.exe '-NoExit -ExecutionPolicy Bypass -NoProfile -Command netsh advfirewall firewall delete rule name=$([IO.Path]::GetFileNameWithoutExtension(\\\\\\\"%1\\\\\\\")) program=\\\\\\\"%1\\\\\\\" dir=out; netsh advfirewall firewall add rule name='\"'([System.IO.Path]::GetFileNameWithoutExtension('%1'))'\"' dir=out action=allow program='\"'%1'\"'}'%1'`\\\"\\\"\""
Other commands I tried
1)
@="powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -NoProfile -Command Start-Process -Verb RunAs powershell.exe '-NoExit -ExecutionPolicy Bypass -NoProfile -Command netsh advfirewall firewall delete rule name=$([IO.Path]::GetFileNameWithoutExtension(\"%1\")) program=\"%1\" dir=out; netsh advfirewall firewall add rule name='\"'([System.IO.Path]::GetFileNameWithoutExtension('%1'))'\"' dir=out action=allow program='\"'%1'\"'}' \"%1\""
@="powershell.exe -NoProfile -ExecutionPolicy Bypass -Command \"Start-Process -Verb RunAs powershell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -NoExit -Command \"netsh advfirewall firewall delete rule name=$([IO.Path]::GetFileNameWithoutExtension(\\\\\\\"%1\\\\\\\")) program=\\\\\\\"%1\\\\\\\" dir=out; netsh advfirewall firewall add rule name=\\\\\\\"$([System.IO.Path]::GetFileNameWithoutExtension('%1'))\\\\\\\" dir=out action=allow program=\\\\\\\"%1\\\\\\\"\"'\""
Powershell
opens when I run the code; but it skips the Administrator Permission (UAC)
prompt before it opens.
I'm not sure exactly; but I think somewhere in the code one or more of these signs "\'
are missing or more.
I would appreciate any help or guidance on this issue. Thank you for your attention and interest in advance.