C# invoking Powershell, DLL could not be loaded -
i having odd problem.. following lines run fine directly in powershell:
1) powercfg -availablesleepstates 2) powercfg -energy
straight forward enough, -energy generates file, has other flags play with.
running line 1 c# works fine (in of wonderful methods throughout site,
powershell s_ps = powershell.create(); s_ps.addscript("powercfg -availablesleepstates"); collection<psobject> results = s_ps.invoke();
(or versions run through pipeline, or create pscommand(), , on)
running same thing on -energy works fine console, if try call through c# starts talking missing 'energy.dll' or 1 of dependencies. dlls (including dependencies) of course there - since runs command line, , verified manually anyway.
visual studio running in admin mode, , on safe side built ap , tried running directly in admin mode too
i have tried manually loading dll
s_ps.addscript(@"[reflection.assembly]::loadfrom('c:\windows\system32\energy.dll') | out-null");
but throws error saying
'could not load file or assembly 'file:///c:\windows\system32\energy.dll' or 1 of dependencies'
does have thoughts on else causing issues? (have run bit, if find solution before else of course post it, been hammering @ of day though no luck)
as far -engery switch command must understand proper , execute without asking assembly. thing since powercfg.exe -energy uses async model execution app needs wait till 60secs results. tried executing follows , worked.my env win 7 pro, i7,64bit
foreach (var v in powershellinterop.runpowershellscript("powercfg -energy")) console.writeline(v); internal static ienumerable runpowershellscript(string script) { powershell ps = powershell.create(); ps.addscript(script); collection<psobject> result = ps.invoke(); foreach (psobject obj in result) { yield return (obj); } }
result
enabling tracing 60 seconds... observing system behavior... analyzing trace data... analysis complete.
energy efficiency problems found.
5 errors 19 warnings 40 informational
see {path}\debug\energy-report.html mor e details.
Comments
Post a Comment