With only the command prompt, is it possible to disable sleep mode when closing the lid of a laptop?
The command you are looking for is powercfg.
Open a command prompt and type
powercfg –q >poweroptions.txt
This will create a text file (poweroptions.txt) with all the GUIDs for the power settings. Open the poweroptions.txt file and find the GUID for the current power scheme. This should be at the very top of the file and will look like this:
Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)
Copy and paste just the GUID (in this example -
381b4222-f694-41f0-9685-ff5bb260df2e) into a new empty text file.
Then scroll through and find the Subgroup GUID for the “Power buttons and lid” actions. Copy and paste this GUID into that same new text file as a separate line.
Now find the Power Setting GUID for “Lid close action” and copy and paste that one under the other two.
Please also note the ‘Possible Setting Index’ numbers for the option that you will want to set it to (disabled is 000).
You will have to run the command once for each power scheme, DC and AC power in order to cover both situations.
The command will look like this:
Powercfg –SETACVALUEINDEX [put power scheme GUID here] [put subgroup GUID here] [put power setting GUID here] 000
I tested this and my command looks like this:
powercfg -SETACVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 000
The second command is for when the user is on battery and is exactly the same except we use the switch
The topic here is How to disable sleep mode via CMD?
Assuming you have configured the lid of your laptop to do nothing when closed:
powercfg -x -standby-timeout-ac 0
(somehow the switch -x doesn't work for me so I've changed it to /x and it works. the rest of the switches stay -standby-timeout-ac)
As shown on Microsoft's Technet page "Powercfg Command-Line Options" (https://technet.microsoft.com/en-us/library/cc748940(v=ws.10).aspx), the command is:
> powercfg -x setting value (the value you're looking at is "standby")
therefore: > powercfg -x -standby-timeout-ac minutes (disable = 0 minutes)
NOTE: ac = connected to electric power / dc = works on battery
(so if you want to disable sleep mode while working on battery power, replace the "ac" with "dc" in the command, so it will look like
powercfg -x -standby-timeout-dc 0)
Based off of the previous answer I wrote a batch file.
@echo off for /f "tokens=4 delims= " %%i IN ('powercfg -q ^| find "Power Scheme GUID:"') do Set StrOne=%%i for /f "tokens=3 delims= " %%i IN ('powercfg -q ^| find "(Power buttons and lid)"') do Set StrTwo=%%i for /f "tokens=4 delims= " %%i IN ('powercfg -q ^| find "(Lid close action)"') do Set StrThree=%%i powercfg -SETACVALUEINDEX %StrOne% %StrTwo% %StrThree% 000
You need to change %%i to %i if trying to run these commands directly in a command prompt (outside of a batch).
Based on the script from Jeremy and Jonas Herdick, I wrote this toggle script, which is localization independent (so also works with German windows) and helps me to disable and restore (to what ever it was before) the lid close action when putting my notebook to it's dock (where the lid needs to closed). And yes, don't forget to re-activate the current powerscheme after every change like KallePower mentioned
@echo off setlocal enabledelayedexpansion for /f "tokens=2 delims=:(" %%i in ('powercfg /GETACTIVESCHEME') do set ACTIVESCHEME=%%i for /f "tokens=2 delims=:(" %%i in ('powercfg -q %ACTIVESCHEME% SUB_BUTTONS LIDACTION ^| findstr "[0-9a-z]*-[0-9a-z]*-[0-9a-z]*-[0-9a-z]*-[0-9a-z]*"') do set FULLPATH=!FULLPATH! %%i for /f "tokens=2 delims=:(" %%i in ('powercfg /q %FULLPATH% ^| findstr "[0-9]x[0-9]*"') do ( set CURRENTSETTINGAC=!CURRENTSETTINGDC! set CURRENTSETTINGDC=%%i ) set CURRENTSETTINGAC=%CURRENTSETTINGAC:~-1% set CURRENTSETTINGDC=%CURRENTSETTINGDC:~-1% powercfg -SETACVALUEINDEX %FULLPATH% 0 powercfg -SETDCVALUEINDEX %FULLPATH% 0 powercfg /s %ACTIVESCHEME% pause powercfg -SETACVALUEINDEX %FULLPATH% %CURRENTSETTINGAC% powercfg -SETDCVALUEINDEX %FULLPATH% %CURRENTSETTINGDC% powercfg /s %ACTIVESCHEME%
Microsoft has a long page on
powercfg command-line options.
You'll probably be reading up on the
-x switch. I've only used
powercfg to change hibernate settings, though.
One more thing. Remember to add "powercfg -S %StrOne%" at the end of the script to activate settings. Else settings will just be set, but not be saved/activated.
REM Disabling all Sleep Parameters @echo off powercfg /x -hibernate-timeout-ac 0 powercfg /x -hibernate-timeout-dc 0 powercfg /x -disk-timeout-ac 0 powercfg /x -disk-timeout-dc 0 powercfg /x -monitor-timeout-ac 0 powercfg /x -monitor-timeout-dc 0 Powercfg /x -standby-timeout-ac 0 powercfg /x -standby-timeout-dc 0 Pause