Search code examples
c#processpowercfg

Calling powercfg /requests from c# gives wrong values


So I have a chunk of code to call powercfg with the /requests option and get the result back from stdout.

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "powercfg";
p.StartInfo.Arguments = "/requests";
p.Start();

string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();

However when I run this code I get entirely different output than when I run the same command on the command line.

In the case of the code version I only get a load of "[DRIVER] ?" values back, but on the command line I get usually 2 or 3 properly formed responses.

I've run my code from the same command prompt window as the same user with the same environment, still no joy.

Any ideas ?


Solution

  • So the actual reason was that my application needed to be compiled for "Any CPU". Setting it to x86 or x64 caused issues with it loading the correct version of one of the dependent libraries.