Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
You guys have any better idea to select the power plan using c# or is it better to run the cmd to select the power plan through C# ?. Any idea why my code not work ? or any better idea ?

What I have tried:

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "powercfg -setactive  8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c";
process.StartInfo = startInfo;
process.Start();
Posted
Updated 6-Aug-17 4:31am

CMD needs a /c switch to execute a process passed as argument, so you'll have to do this:
C#
startInfo.Arguments = "/c powercfg -setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c";
 
Share this answer
 
Comments
Karthik_Mahalingam 6-Aug-17 23:45pm    
5
Okay, just find out the Answer.

u guys can : insert the
Process.Start("powercfg", "-setactive  GUID_VALUE");


Example GUID VALUE:

Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)
Power Scheme GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c (High performance) *
Power Scheme GUID: a1841308-3541-4fab-bc81-f71556f20b4a (Power saver)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900