I am having a slightly odd problem.. the following lines run fine directly in powershell:
1) powercfg -AVAILABLESLEEPSTATES
2) powercfg -energy
Straight forward enough, -energy generates its file, has other flags I could play with.
Running line 1 from C# works fine too (in any of the wonderful methods throughout this site, like
Powershell s_ps = PowerShell.Create();
s_ps.AddScript("powercfg -AVAILABLESLEEPSTATES");
Collection<PSObject> results = s_ps.Invoke();
(or the versions that run everything through a Pipeline, or create PSCommand(), and so on)
Running the same thing on the -energy works fine from the console, but if I try to call it through C# it starts talking about missing 'energy.dll' or one of its dependencies. All the dlls (including dependencies) are of course there - since it runs from command line, and verified manually anyway.
Visual Studio is running in Admin mode, and just to be on the safe side I built the ap and tried running that directly in Admin mode too
I have tried manually loading the dll
s_ps.AddScript(@"[Reflection.Assembly]::LoadFrom('C:\Windows\System32\energy.dll') | Out-Null");
But it just throws an extra error saying it
'could not load file or assembly 'file:///C:\Windows\System32\energy.dll' or one of its dependencies'
Does anyone have any thoughts on what else would be causing issues? (Have to run for a bit, but if I find a solution before someone else I will of course post it, been hammering at it for most of the day though with no luck)