【问题标题】:"An error occurred when loading the system Windows PowerShell snap-ins"“加载系统 Windows PowerShell 管理单元时出错”
【发布时间】:2012-06-05 23:49:12
【问题描述】:

尝试在我的 C# 代码中执行 powershell 脚本。在 Windows 7 上的 VS 2010 中使用 .NET Framework v. 4.0.30319 SP1Rel。

我有以下 dll 文件作为参考:

C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\system.management.automation.dll

我包括:

using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

然后当我运行以下命令时:

RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create(); // here
Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);

它在第一行崩溃,但有以下异常:

{"An error occurred when loading the system Windows PowerShell snap-ins. Please contact Microsoft Support Services."}

内部异常:

{"Unable to access Windows PowerShell PowerShellEngine registry information."}

我能够在 cmd 中运行“Powershell.exe”(版本 2 或 1),它运行良好,并且我的项目可以正常编译。我读了这个问题(http://social.msdn.microsoft.com/Forums/eu/biztalkesb/thread/a807bee7-531a-4990-b8da-47a7e6e3e099),他们谈到了一些注册。钥匙,但他忘了确切地提到他做了什么来修复它。非常感谢任何帮助!

【问题讨论】:

  • 如果您以本地管理员身份运行应用程序是否有效?
  • 这个链接有帮助吗? stackoverflow.com/questions/2094694/…
  • 发现了问题。引用了错误的dll。文件和正确的文件可以找到从 powershell v.2 运行“echo ([PSObject].Assembly.Location)”
  • 请将您的解决方案作为答案发布并接受。它有助于结束问题。

标签: c# powershell windows-7


【解决方案1】:

我打开了一个终端并运行了 powershell v2,然后我运行了以下命令:

"echo ([PSObject].Assembly.Location)"

这将为您提供正在使用的 dll 的正确路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-22
    • 1970-01-01
    • 1970-01-01
    • 2014-01-23
    • 1970-01-01
    相关资源
    最近更新 更多