试图在我的 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),他们谈到了一些注册。钥匙,但他忘了具体说明他做了什么来修复它。非常感谢任何帮助!