我已经编写了这个PowerShell脚本,可以自动阻止Windows防火墙中文件夹内的可执行文件。
防火墙密钥的默认名称和值为“防火墙阻止程序”。
命令键的默认名称和字符串值为:
我该如何在 Windows 11 的新现代上下文菜单样式中添加此上下文菜单选项?
到目前为止,我找到了这个链接,但是无法确定是否必须将这个简单的 PowerShell 脚本创建为程序才能将其添加到菜单中。
链接:https://blogs.windows.com/windowsdeveloper/2021/07/19/extending-the-context-menu-and-share-dialog-in-windows-11/
$currentdir = get-Location
cd $currentdir
function FirewallBlock {
param ($exes)
$exes | ForEach-Object { New-NetFirewallRule -DisplayName "$_.name inbound" -Direction Inbound -Action Block -Profile Any -Program $_.DirectoryName }
$exes | ForEach-Object { New-NetFirewallRule -DisplayName "$_.name outbound" -Direction Outbound -Action Block -Profile Any -Program $_.DirectoryName }
}
$programs = dir -Recurse *.exe
FirewallBlock ($programs)
通过创建以下两个注册表键,将其添加到旧样式上下文菜单中:
Computer\HKEY_CLASSES_ROOT\Directory\Background\shell\Firewall
并且这里
Computer\HKEY_CLASSES_ROOT\Directory\Background\shell\Firewall\command
防火墙密钥的默认名称和值为“防火墙阻止程序”。
命令键的默认名称和字符串值为:
powershell -command "Start-Process pwsh.exe -ArgumentList '-file C:\Users\UserName\OneDrive\Desktop\Firewall.ps1' -Verb runAs"
我该如何在 Windows 11 的新现代上下文菜单样式中添加此上下文菜单选项?
到目前为止,我找到了这个链接,但是无法确定是否必须将这个简单的 PowerShell 脚本创建为程序才能将其添加到菜单中。
链接:https://blogs.windows.com/windowsdeveloper/2021/07/19/extending-the-context-menu-and-share-dialog-in-windows-11/
IExplorerCommand
接口。通过快速搜索,我找到了C++的示例代码。 - zett42