Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
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 '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
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 '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

4 Answers 4

up vote 7 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 2 days ago

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
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 '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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.