Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With only the command prompt, is it possible to disable sleep mode when closing the lid of a laptop?

share|improve this question
Out of curiosity, is this just a purely theoretical question or is there some specific reason you need to do this? I ask because there might be other ways of accomplishing it if that's the case. – Shinrai Dec 14 '11 at 18:52
Well I need to do it remotely and I only have the command prompt acesss of the laptop. – kb67 Dec 14 '11 at 19:51
Might it not be easier just to walk the user of the laptop through doing it? I think iglvzx's comment is right and there's no way to easily change the lid action short of manual registry edits. – Shinrai Dec 14 '11 at 19:59
Well, I've been proven wrong, there is a way of doing it via powercfg, but I do think it's involved enough that it still might be easier just to talk them through it. – Shinrai Dec 14 '11 at 20:32
up vote 9 down vote accepted

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 –SETDCVALUEINDEX.

Here is the official Powercfg command-line options page from Microsoft for further reference.

share|improve this answer
Hi David - I'm glad to see that Microsoft has people doing outreach on sites like this, it's encouraging. It is not necessary to sign your posts on any Stack Exchange site, though, and actually discouraged - this is what your user badge is for. – Shinrai Dec 14 '11 at 20:24
Shrinrai, Sorry, I visit so many different forums every day it's hard to keep all the features straight. I will look at my user badge. – WinOutreach4 Dec 14 '11 at 20:29
powercfg seems like a fine example of "how not to write a command line tool" :/ – Martin von Wittich Aug 28 '14 at 11:12

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

share|improve this answer

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.

share|improve this answer
powercfg does not have any options for changing the lid close action. The power options are stored in the Registry under HKEY_CURRENT_USER\Control Panel\PowerCfg\GlobalPowerPolicy but it is unclear which values in the binary data go with which setting. – iglvzx Dec 14 '11 at 19:16
Thanks for the feedback. I was unsure but I'm glad I linked to the same place as David :-) – user3463 Dec 16 '11 at 7:19

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.

share|improve this answer

I improved Jeremy's script to toggle the the lid close action between sleep and do nothing depending on the state in the current scheme. It changes the setting for all schemes.

It can be adapted to change different settings or change only the current scheme's setting.

@echo off

:get current scheme
for /f "tokens=4 delims= " %%j IN ('powercfg -getactivescheme ^| find "Power Scheme GUID: "') do SET currentscheme=%%j

:get close-to-lid state
powercfg /q %currentscheme% SUB_BUTTONS LIDACTION | find "Current AC Power Setting Index: 0x00000001" > NUL
SET newstate=00%errorlevel%

:set close-to-lid state for all power schemes
IF %newstate% EQU 1 echo Closing the lid will now send to sleep...
IF %newstate% EQU 0 echo Closing the lid will now do nothing...
for /f "tokens=4 delims= " %%i IN ('powercfg -l ^| find "Power Scheme GUID: "') do (
share|improve this answer

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 (
powercfg /s %ACTIVESCHEME%
powercfg /s %ACTIVESCHEME%
share|improve this answer

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" (, 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)

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .