打开组策略编辑器:按下Win + R,输入 gpedit.msc,回车。
在左侧面板中依次展开“计算机配置”、“Windows设置”、“安全设置”、“软件限制策略”。
在右侧面板中找到限制应用程序执行的条目,然后双击它。
在打开的对话框中,切换到“执行受限制的应用程序”选项卡。
如果下面的选项中只有PowerShell.exe被列出,那么说明只允许运行PowerShell。点击“新建”按钮,在弹出的对话框中输入需要允许执行的程序路径和名称,例如:"C:\Windows\system32\notepad.exe",然后确定。
重新启动计算机,然后再次尝试运行被限制的程序,应该就能够正常运行了。
代码示例(使用PowerShell脚本):
$policyPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\safer\CodeIdentifiers\0\Paths" $notepadAllowedPath = "C:\Windows\system32\notepad.exe"
if (Test-Path $policyPath) { $existingPaths = Get-ItemProperty -Path $policyPath if ($existingPaths -match $notepadAllowedPath) { Write-Output "Notepad is already allowed to run." } else { Write-Output "Adding Notepad to allowed paths." New-ItemProperty -Path $policyPath -Name "C:\Windows\system32\notepad.exe" -Value 1 -PropertyType DWORD } } else { Write-Warning "Software restriction policy is not set." }