C#winform:使用CMD选择POWERPLAN(powercfg) [英] C# winform: using CMD to select POWERPLAN (powercfg)
问题描述
您最好使用c#选择电源计划,还是运行cmd以通过C#选择电源计划更好?知道为什么我的代码无效吗?或者更好的主意?
我的尝试:
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();
推荐答案
CMD需要一个/ c
切换来执行一个进程作为参数传递,所以你必须这样做:
CMD needs a/c
switch to execute a process passed as argument, so you'll have to do this:
startInfo.Arguments = "/c powercfg -setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c";
好的,只是找出答案。
u家伙可以:插入
Okay, just find out the Answer.
u guys can : insert the
Process.Start("powercfg", "-setactive GUID_VALUE");
示例GUID VALUE:
电源方案GUID:381b4222-f694-41f0-9685-ff5bb260df2e(平衡)
电源方案GUID:8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c(高性能)*
电源方案GUID:a1841308-3541-4fab-bc81-f71556f20b4a(节电器)
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)
这篇关于C#winform:使用CMD选择POWERPLAN(powercfg)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!