Change what closing the lid does, from the commandline?

8

5

I wonder if anybody knows a utility, or command, which can change this setting in windows in one click. I often need to change it on my laptop whether I want it to do nothing when the lid is closed or go to sleep.

I'm sure it's possible to change somehow from the command line.

bame2

Posted 2015-02-07T08:24:30.647

Reputation: 91

Answers

19

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

AC for the "Plugged In" action and DC for the "On Battery" action.


Hope this helps.

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.

Greenonline

Posted 2015-02-07T08:24:30.647

Reputation: 1 690

1

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

user373230

Posted 2015-02-07T08:24:30.647

Reputation:

1

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

Marcus Mangelsdorf

Posted 2015-02-07T08:24:30.647

Reputation: 734