更新时间:2023-02-03 21:45:28
默认设置ExecutionPolicy
命令尝试设置计算机范围值。你只需要你的C#应用程序的范围内更改设置,所以你应该添加 -Scope过程
选项添加到命令。
The default Set-ExecutionPolicy
command attempts to set the machine-wide value. You only want to change the setting within the scope of your C# application, so you should add the -Scope Process
option to the command.
使用获取帮助的Set-ExecutionPolicy -detailed
显示以下信息:
注:要更改执行策略默认(LOCALMACHINE)范围,启动Windows PowerShell使用以管理员身份运行选项
NOTE: To change the execution policy for the default (LocalMachine) scope, start Windows PowerShell with the "Run as administrator" option.
...它也描述了 -Scope
选项。
... and it also describes the -Scope
option.
这具有的优势 仅 的影响的执行策略脚本从C#应用程序中运行,它不会不必要地更改默认的PowerShell行为的执行策略。 (所以这是一个安全很多,特别是如果你可以让你的应用程序运行的脚本的有效性的保证。)
This has the advantage of only impacting the execution policy for scripts run from your C# application, and it doesn't unnecessarily change the execution policy for the default PowerShell behavior. (So it's a lot safer, especially if you can make guarantees about the validity of the scripts your application runs.)