你能看一下代码并告诉我它为什么不能设置我的powerconfig吗?它作为批处理脚本启动时工作正常(所以配置文件没问题),但是当我在C#下运行相同的命令时却没有#
public void setPowerProfileLaptop()
{
string strCmdText;
strCmdText = "/C REGEDIT /s C:\\Configs\\Enable_Sleep.reg";
Process.Start("CMD.exe", strCmdText);
strCmdText = "/C POWERCFG -Import C:\\Configs\\Chillblast.pow affd6254-c7dd-457c-a259-da407eb5ac00";
Process.Start("CMD.exe", strCmdText);
strCmdText = "/C POWERCFG -SetActive affd6254-c7dd-457c-a259-da407eb5ac00";
Process.Start("CMD.exe", strCmdText);
}
答案 0 :(得分:2)
以下是Blorgbeard在评论中建议的固定代码
public void setPowerProfileLaptop()
{
string strCmdText;
strCmdText = "/C REGEDIT /s C:\\Configs\\Enable_Sleep.reg";
var enableSleep = Process.Start("CMD.exe", strCmdText);
enableSleep.WaitForExit();
strCmdText = "/C POWERCFG -Import C:\\Configs\\Chillblast.pow affd6254-c7dd-457c-a259-da407eb5ac00";
var importCFG = Process.Start("CMD.exe", strCmdText);
importCFG.WaitForExit();
strCmdText = "/C POWERCFG -SetActive affd6254-c7dd-457c-a259-da407eb5ac00";
var setActive = Process.Start("CMD.exe", strCmdText);
setActive.WaitForExit();
}