c# - "An error occurred when loading the system Windows PowerShell snap-ins" -


trying execute powershell script in c# code. using .net framework v. 4.0.30319 sp1rel in vs 2010 on windows 7.

i have following dll file reference:

c:\program files (x86)\reference assemblies\microsoft\windowspowershell\v1.0\system.management.automation.dll

and include:

using system.collections.objectmodel; using system.management.automation; using system.management.automation.runspaces; 

then when run following commands:

runspaceconfiguration runspaceconfiguration = runspaceconfiguration.create(); // here runspace runspace = runspacefactory.createrunspace(runspaceconfiguration); 

it crashes on first line following exception:

{"an error occurred when loading system windows powershell snap-ins. please contact microsoft support services."} 

inner exception:

{"unable access windows powershell powershellengine registry information."} 

i able run "powershell.exe" (version 2 or 1) in cmd , works fine , project compiles should. read question (http://social.msdn.microsoft.com/forums/eu/biztalkesb/thread/a807bee7-531a-4990-b8da-47a7e6e3e099) talked reg. keys forgot mention did fix it. appreciate help!

i opened terminal , ran powershell v2 , ran following command:

"echo ([psobject].assembly.location)" 

which give correct path dll being used.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -