首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将一行powershell设置为睡眠,将休眠设置为关闭

将一行powershell设置为睡眠,将休眠设置为关闭
EN

Stack Overflow用户
提问于 2015-11-19 05:41:54
回答 2查看 30.8K关注 0票数 6
代码语言:javascript
复制
powershell -Command "& {c:\windows\system32\powercfg.exe -change -monitor-timeout-ac 0; c:\windows\system32\powercfg.exe - change - monitor - timeout - dc 0; c:\windows\system32\powercfg.exe - change - disk - timeout - ac 0; c:\windows\system32\powercfg.exe - change - disk - timeout - dc 0; c:\windows\system32\powercfg.exe - change - standby - timeout - ac 0; c:\windows\system32\powercfg.exe - change - standby - timeout - dc 0; c:\windows\system32\powercfg.exe - change - hibernate - timeout - ac 0; c:\windows\system32\powercfg.exe - change - hibernate - timeout - dc 0 }"

我该如何正确地编写这段代码呢?我想一次设置多个电源选项来关闭休眠和睡眠模式。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-11-22 22:42:30

代码语言:javascript
复制
var newProcessInfo = new System.Diagnostics.ProcessStartInfo();
        newProcessInfo.FileName = @"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe";
        newProcessInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; // hide processes as they happen
        newProcessInfo.Verb = "runas"; // run as administrator
        newProcessInfo.Arguments = @"-executionpolicy unrestricted -Command ""c:\power\powercfg.bat"""; //you can use the -noexit to troubleshoot and see the commands
        System.Diagnostics.Process.Start(newProcessInfo);

批处理文件(c:\power\powercfg.bat):

代码语言:javascript
复制
@echo off
powercfg.exe -x -monitor-timeout-ac 0
powercfg.exe -x -monitor-timeout-dc 0
powercfg.exe -x -disk-timeout-ac 0
powercfg.exe -x -disk-timeout-dc 0
powercfg.exe -x -standby-timeout-ac 0
powercfg.exe -x -standby-timeout-dc 0
powercfg.exe -x -hibernate-timeout-ac 0
powercfg.exe -x -hibernate-timeout-dc 0

这样做效果最好。

票数 10
EN

Stack Overflow用户

发布于 2022-01-28 20:11:53

我喜欢这个答案,非常有用,谢谢你的回复,我是说这个答案

我喜欢这个答案,非常有用,谢谢你的回复,我是说这个答案

代码语言:javascript
复制
@echo off
powercfg.exe -x -monitor-timeout-ac 0
powercfg.exe -x -monitor-timeout-dc 0
powercfg.exe -x -disk-timeout-ac 0
powercfg.exe -x -disk-timeout-dc 0
powercfg.exe -x -standby-timeout-ac 0
powercfg.exe -x -standby-timeout-dc 0
powercfg.exe -x -hibernate-timeout-ac 0
powercfg.exe -x -hibernate-timeout-dc 0
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33790965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档