Prevent windows 10 from sleeping for next lid closing only

Prevent windows 10 from sleeping for next lid closing only

Sometimes I let my computer (Lenovo laptop under Windows 10) do stuff that takes a while (e.g. scientific computation). When it does that, I would like to be able to close its lid without it going to sleep.

The problem is that I would also like to keep it’s default behavior where it goes to sleep when I close it, most of the time.

The way I’d like it to work would be that, if I don’t do anything and close the lid, it goes to sleep. If I press some arbitrary key combination though, it would ignore the next time I close the lid, and stay awake until I open it again.

Ideally, this behavior would be the same plugged in or not. I know I can change that under «power management», but I do that often, and it would be nice to have a shortcut for it.

Can anybody think of a way to do that, or any trick to emulate this kind of behavior?

Thanks in advance.

Antwort1

To prevent the computer from sleeping, you could use a program such as Caffeine or Insomnia.

Alternatively, you may disable sleep on lid close and re-enable it later. If doing so manually is too onerous, you can do that via a command that you may put in a batch file stored on the desktop.

See the toggle script, for disabling and restoring the lid close action to whatever it was before, in this answer (but the other answers might also be pertinent).

Here is a slightly modified version of the script :

@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 (
    set CURRENTSETTINGAC=!CURRENTSETTINGDC!
    set CURRENTSETTINGDC=%%i
)
set CURRENTSETTINGAC=%CURRENTSETTINGAC:~-1%
set CURRENTSETTINGDC=%CURRENTSETTINGDC:~-1%
powercfg -SETACVALUEINDEX %FULLPATH% 0
powercfg -SETDCVALUEINDEX %FULLPATH% 0
powercfg /s %ACTIVESCHEME%
pause Waiting to re-enable sleep on lid close ...
powercfg -SETACVALUEINDEX %FULLPATH% %CURRENTSETTINGAC%
powercfg -SETDCVALUEINDEX %FULLPATH% %CURRENTSETTINGDC%
powercfg /s %ACTIVESCHEME%

verwandte Informationen