如何设置ExecutionPolicy:拒绝访问注册表项


22

我以管理员身份运行Windows Server 2008,并尝试将ExecutionPolicy设置为PowerShell v2的Remotesigned,如下所示:

Set-ExecutionPolicy RemoteSigned

但是我得到了这个错误:

Set-ExecutionPolicy : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft
.PowerShell' is denied.
At line:1 char:20
+ Set-ExecutionPolicy <<<<  RemoteSigned
    + CategoryInfo          : NotSpecified: (:) [Set-ExecutionPolicy], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetExecutionPolicyComma
   nd

如何解决这个问题?

Answers:


24

右键单击Powershell快捷方式,然后选择“以管理员身份运行”


5
另请注意,如果您使用的是64位操作系统,则需要为32位和64位版本的PowerShell设置执行策略。
乔伊

您无需以管理员身份运行它,只需-Scope CurrentUser按照Janus答案的建议运行它
-CharlesB

12

Stephen Jennings在StackOverflow上回答了相同的问题

Set-ExecutionPolicy Unrestricted -Scope CurrentUser

这将为当前用户(存储在HKEY_CURRENT_USER中)而不是本地计算机(HKEY_LOCAL_MACHINE)设置执行策略。


3
谢谢。这是正确的答案,并非所有人都具有管理员权限,但这仍然有效。
查尔斯·克莱顿

4

如果“以管理员身份运行”对您不起作用(起初对我而言不是),或者如果您想要一个永久解决方案,我可以通过将权限直接添加到Windows注册表中找到解决方法。完成此操作后,当我调用get-ExecutionPolicy时,它不再受到限制。

它等效于set-ExecutionPolicy RemoteSigned,并且可以实际运行。

在这里写:http//kyleclegg.com/powershell/

希望这可以帮助。


0

我发现对该错误起作用的唯一解决方案是运行regedt32并向下钻取键,然后将用户的权限从读取更改为完全控制。服务器上的本地权限优先于域管理员权限。


考虑到已经存在其他两个答案,这不是一个很好的答案……
HopelessN00b 2012年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.