Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a one line powershell for sleep and hibernate to turn off

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 }"

How would I write this code correctly? I want to set multiple power options at once to turn off hibernate and sleep modes.

like image 782
DDJ Avatar asked Nov 18 '15 21:11

DDJ


People also ask

How do I turn off hibernation in PowerShell?

Right-click on Start button and click on Windows PowerShell (Admin) or Command Prompt (Admin). 2. On the Command Prompt Window, type powercfg –h off and press the Enter key on the keyboard of your computer. Once the Command is executed, Hibernate Mode will be disabled and “hiberfil.

Is there a command line to disable sleep on Windows 10?

This is next to the Windows 10 logo. Then type Command Prompt into the search bar. Next, click Run as administrator. Then type powercfg.exe /hibernate off into the Command Prompt.

How do I hibernate PowerShell?

Press Windows logo key and X key, then select Command Prompt (Admin) or Windows PowerShell (Admin). In the launched window, type: powercfg /hibernate on and press enter to enable hibernation.


1 Answers

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);

Batch file (c:\power\powercfg.bat):

@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

This worked best.

like image 160
DDJ Avatar answered Oct 21 '22 16:10

DDJ