【发布时间】:2020-05-14 22:59:36
【问题描述】:
在我的 C# 应用程序中,我尝试创建一个 RunSpace 来调用一些 Powershell 脚本。但是,当它到达实际创建它的代码时,它会失败并出现以下错误:
var implementedHost = new implementedPSHost();
using (var rs = RunspaceFactory.CreateRunspace(customPSHost))
{
cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.At line:1 char:3+ . .\Scripts\loadFunctions.ps1+
按照其他地方的建议,我运行了一个 Powershell 窗口并执行了Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted,但这并没有帮助。错误仍然发生。有没有人知道如何解决这个问题?
【问题讨论】:
-
C# 应用程序是否在同一用户的安全上下文中运行?
-
@RohinSidharth 我该如何确认?
-
你能分享你正在使用的完整代码吗,
using语句中并没有真正生成错误,而是当你尝试启动脚本时,我们需要查看全文看看你在做什么。
标签: c# powershell