0

你能看一下代码并告诉我为什么它不会设置我的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);
    }
4

1 回答 1

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();
    }
于 2014-08-14T08:46:30.107 回答