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

  • 1
    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, 2011 at 18:52
  • Well I need to do it remotely and I only have the command prompt acesss of the laptop.
    – kb67
    Dec 14, 2011 at 19:51
  • 1
    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, 2011 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, 2011 at 20:32

8 Answers 8


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.

  • 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, 2011 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.
    – dwolters
    Dec 14, 2011 at 20:29
  • 1
    powercfg seems like a fine example of "how not to write a command line tool" :/ Aug 28, 2014 at 11:12

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)

  • 1
    This works on Win 7 and Win 10, thanks ! The only requirement - to run CMD as Administrator.
    Aug 17, 2017 at 14:29
  • 1
    The problem with -x might be that it was a full dash, not the normal negative symbol. Aug 30, 2017 at 17:14
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


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 (
powercfg /s %ACTIVESCHEME%
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.

  • 1
    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, 2011 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, 2011 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.


Try NoDoz. Once installed, you can run nodoz from your cmd prompt (or PowerShell terminal) to keep your system from sleeping indefinitely. Or, you can pass in a timeout parameter like -t 6h13m to have the program automatically end after an arbitrary amount of time.

You must log in to answer this question.

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