2012-06-05 10 views
5

C#コードでpowershellスクリプトを実行しようとしています。 .NET Frameworkの使用v 4.0.30319 SP1Rel VS 2010でのWindows 7上で"システムWindows PowerShellスナップインの読み込み中にエラーが発生しました"

私はリファレンスとして、以下のdllファイルがあります。

C:\プログラムファイル(x86の)\リファレンスアセンブリ\マイクロソフト\ 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."} 

内部例外:それは、以下の例外を除いて、最初の行にクラッシュ

私はCMDで "​​たpowershell.exe"(バージョン2または1)を実行することができる午前

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

とそれはうまく動作し、私のプロジェクトは必要に応じてコンパイルされます。私はこの質問を読んで(http://social.msdn.microsoft.com/Forums/eu/biztalkesb/thread/a807bee7-531a-4990-b8da-47a7e6e3e099)、彼らはいくつかのregについて話しました。彼はそれを修正するために何をしたのかを忘れてしまった。本当に助けてくれてありがとう!

+0

アプリケーションをローカル管理者として実行すると機能しますか? – Dan

+0

adminとしてログインしています – chikuba

+0

このリンクは役に立ちますか? http://stackoverflow.com/questions/2094694/how-can-i-run-powershell-with-the-net-4-runtime – Dan

答えて

3

私は、ターミナルを開いて、PowerShellのV2を走ったし、私は、次のコマンドを実行しました:

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

使用されているDLLにあなたの正しいパスを与えるであろう。

関連する問題