有一个Context Menu
,我已经分配给鼠标右键为Windows Firewall
。我正在使用以下代码删除安全规则。
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'"
字符串
同样,我希望它在删除后使用单个脚本重新添加此代码为"action=allow"
。
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'`\\\"\\\"\""
型
我尝试的其他命令
第一章
@="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
在我运行代码时打开;但是它在打开之前跳过了Administrator Permission (UAC)
提示符。
我不太确定但我认为在代码的某个地方,这些符号中的一个或多个"\'
丢失了或多个。
我将感谢在这个问题上的任何帮助或指导。提前感谢您的关注和兴趣。
1条答案
按热度按时间nuypyhwy1#
.reg
文件值中的语法注意事项以及对powershell.exe
(Windows PowerShell CLI)的调用将在this answer的底部部分针对您的上一个问题进行讨论。要使此处显示的值适应您的新用例,请执行以下操作:
netsh
调用进行建模。字符串
;
,PowerShell的语句分隔符,将此调用直接附加到正在运行的调用,这意味着它 * 正好位于关闭的'
* 内部(即在'...'
字符串的结束'
之前,该字符串包含Start-Process
调用的位置隐含的-ArgumentList
值):型