How to customize the behavior of the system when closing the laptop lid via the command line
By default, Windows laptops go to sleep when the lid is closed. This behavior can be changed by standard means, or through the command line.
Why is this needed?
The natural question is why do something through the command line, when you can make everything easier through the interface? As I found out, there are users who want to frequently change the action when closing the laptop lid. At the same time, it is inconvenient to open the settings every time.
Instead, you can configure a utility like AutoHotkey and manipulate the circuits by simply pressing a hotkey. By analogy, you can change and manage other shutdown options for Windows.
How to find out which power scheme is used
Basic power schemes in Windows have the following meanings:
Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Сбалансированная) Power Scheme GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c (Высокая производительность) Power Scheme GUID: a1841308-3541-4fab-bc81-f71556f20b4a (Экономия энергии)
To verify this, open a command prompt and run the command
An asterisk will indicate the currently selected scheme. In my case, this is "381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)" and using her example, I will show how to change the action when closing the laptop lid.
How to get power plan settings
Now we need to get the parameters of the current power scheme. To do this, run the command
powercfg -Q 381b4222-f694-41f0-9685-ff5bb260df2ewhere you need to specify your schema UID.
When you run the command, you will get the following settings sheet:
How to change the power scheme parameters
The easiest way is to copy the resulting text into a notepad. If you have Windows in Russian, find in the text the lines with the values "Power buttons and lid" and "Action when the lid is closed." Their UID
You can specify any of the available parameters for the schema:
Possible Setting Index: 000 Possible Setting Friendly Name: Ничего не делать Possible Setting Index: 001 Possible Setting Friendly Name: Сон Possible Setting Index: 002 Possible Setting Friendly Name: Гибернация Possible Setting Index: 003 Possible Setting Friendly Name: Выключение
Thus, to change the behavior of the circuit, you need to execute these two commands in turn:
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
- SETACVALUEINDEX - switches the circuit when operating from an outlet;
- SETDCVALUEINDEX - toggles the circuit when running on battery power;
- 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 - UIDs for Power Button and Cover and Action;
- 3 - action when an event occurs.
Accordingly, you can create a bat-file with the above command and configure its automatic execution via AutoHotkey, or simply make a shortcut for it.
Comments powered by Talkyard.