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.


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 (
powercfg /s %ACTIVESCHEME%
pause Waiting to re-enable sleep on lid close ...
powercfg /s %ACTIVESCHEME%
  • That's exactly what I needed, thank you very much! I'm probably going to find out easily, but anyone knows a way to execute a batch file via custom global shortcut? – Silver Duck Aug 21 '18 at 7:32
  • What do you mean by "custom global shortcut" ? – harrymc Aug 21 '18 at 7:55
  • I mean a custom keyboard shortcut that I could press at anytime to launch the script, without having to go click on the batch file. – Silver Duck Aug 21 '18 at 8:00
  • AutoHotkey is your friend. See also this post. – harrymc Aug 21 '18 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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