Change what closing the lid does, from the commandline?

Taken from Set On Lid Close Power Option. There is also a script or two on this page, but the method reproduced below is the best, IMHO.


You can set it through powercfg commands.

The pre-configured schemes have the following GUIDs:

Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e  (Balanced)
Power Scheme GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c  (High performance)
Power Scheme GUID: a1841308-3541-4fab-bc81-f71556f20b4a  (Power saver)

I'll use the Balanced scheme for my examples, but you would use the GUID provided by:

powercfg -GETACTIVESCHEME

You can find the GUIDs for subgroups and power settings as well as the index values for each power setting by running a query command with your scheme GUID:

powercfg -Q 381b4222-f694-41f0-9685-ff5bb260df2e

Looking through the output, you will discover that the subgroup GUID you want is:

Subgroup GUID: 4f971e89-eebd-4455-a8de-9e59040e7347  (Power buttons and lid)

and the power setting:

Power Setting GUID: 5ca83367-6e45-459f-a27b-476b1d01c936  (Lid close action)

with index options:

Possible Setting Index: 000
Possible Setting Friendly Name: Do nothing
Possible Setting Index: 001
Possible Setting Friendly Name: Sleep
Possible Setting Index: 002
Possible Setting Friendly Name: Hibernate
Possible Setting Index: 003
Possible Setting Friendly Name: Shut down

So in order to configure your system to shut down when the lid is closed, you would run:

powercfg -SETACVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 3
powercfg -SETDCVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 3

Note: These two lines are identical, apart from:

  • AC in SETACVALUEINDEX for the "Plugged In" action, and;
  • DC in SETDCVALUEINDEX for the "On Battery" action.

Additional Note

From this post:

Settings made via the command line must be followed with

powercfg -setactive <GUID>`

That is to say, for 'Balanced'

powercfg -setactive 381b4222-f694-41f0-9685-ff5bb260df2e

Please note that I have not block quoted, as it messed up the rather long code lines. So for the sake of formatting, I have left it unquoted.


The following seems the easiest and also somewhat readable way to change the behavior from command line for the currently active power scheme (thanks to w17t's answer and this TenForums post):

DoNothingWhenClosingTheLid.bat

::Do nothing when you close the lid
powercfg /setACvalueIndex scheme_current sub_buttons lidAction 0
powercfg /setDCvalueIndex scheme_current sub_buttons lidAction 0

::Re-activate current scheme to make settings take effect immediately
powercfg /setActive scheme_current

GoToSleepWhenClosingTheLid.bat

::Go to sleep/standby mode when you close the lid
powercfg /setACvalueIndex scheme_current sub_buttons lidAction 1
powercfg /setDCvalueIndex scheme_current sub_buttons lidAction 1

::Re-activate current scheme to make settings take effect immediately
powercfg /setActive scheme_current

powercfg supports aliases for guids (scheme names, groups etc)

@echo off

powercfg /s scheme_min
rem scheme_min is high performance

powercfg /setacvalueindex scheme_min sub_buttons lidaction 0
rem under buttons group; plugged in

powercfg /setdcvalueindex scheme_min sub_buttons lidaction 0

rem dc means on battery

rem check with powercfg.cpl gui

rem use powercfg /aliases for aliases instead of guid numbers

rem query with powercfg /q

this script above would switch to high performance scheme and set the lid action (When I close the lid:) under it to be None on both cases (either plugged or when on battery).

it is basically three lines of code as the rest are almost just comments (remarks).