Guides

Is there a caffeinate command for Windows?

On a Mac, caffeinate keeps the computer awake while a command runs, then lets it sleep again. Windows has no built-in command like it. But Windows has the same mechanism underneath: apps can ask it not to sleep with an official request called SetThreadExecutionState. Video players and presentation apps use it. Here are the practical equivalents.

1. Turn off sleep with powercfg (simple, but permanent)

powercfg /change standby-timeout-ac 0

This sets "sleep after" to never while plugged in (standby-timeout-dc is the battery version). It stays that way until you set it back, for example powercfg /change standby-timeout-ac 30 for 30 minutes. Unlike caffeinate, nothing undoes it for you.

2. A PowerShell one-liner (closest to caffeinate -t)

This asks Windows to stay awake for 2 hours, then stops. Press Ctrl + C or close the window to stop early.

$k = Add-Type -Name P -Namespace W -PassThru -MemberDefinition '[DllImport("kernel32.dll")] public static extern uint SetThreadExecutionState(uint f);'
$end = (Get-Date).AddHours(2); while ((Get-Date) -lt $end) { $null = $k::SetThreadExecutionState(1); Start-Sleep -Seconds 30 }

Every 30 seconds it tells Windows "the system is in use" (1 is ES_SYSTEM_REQUIRED), which resets the idle-sleep timer. The screen can still turn off. To keep the display on as well, use 3 instead of 1 (adding ES_DISPLAY_REQUIRED). Change AddHours(2) to whatever you need.

caffeinate flags, Windows style

3. Check what is keeping Windows awake

In an administrator Command Prompt, this lists the apps currently asking Windows to stay awake:

powercfg /requests

Handy when a PC refuses to sleep, or to confirm a keep-awake app is working.

4. A tray app

If you'd rather click than type, a tray app does the same thing with a timer. Microsoft's PowerToys includes one called Awake. Keeplit (below) is a small standalone one with timed sessions, safeguards, and a closed-lid option.

What none of these can do

Like caffeinate, they only stop automatic sleep. Choosing Sleep, pressing the power button, closing the lid (unless you change the lid setting) or a critically low battery still put the PC to sleep.