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) を読んで、reg について話しました。キーを修正しましたが、彼はそれを修正するために何をしたかを正確に言及するのを忘れていました。どんな助けにも本当に感謝します!