Desk2Mob

Desk2Mob

Desk2Mob

How to Make a Simple Caffeinate-Style Application for Windows

On macOS, the caffeinate command keeps the system awake during long-running tasks — scripts, downloads, backups, or remote sessions that shouldn't be interrupted by sleep.

Windows doesn't have a built-in equivalent, but a batch file and a short PowerShell script can do the same job.

Windows already has a few ready-made ways to do this — PowerToys includes an Awake module, and there's the long-standing Caffeine utility. This is the DIY version: nothing to install, and you can see exactly what it's doing.

The idea is simple: send a harmless key press at a regular interval so Windows does not treat the machine as completely idle. Scroll Lock is a reasonable choice here because it usually has very little effect on normal work.

Why you'd want this

  • Watching a dashboard
  • Keeping the local machine from sleeping during a remote session
  • Preventing the screen from sleeping during a temporary task
  • Keeping a development process visible while monitoring logs

How the solution works

  • Double-click the batch file — it launches PowerShell.
  • PowerShell toggles Scroll Lock on, waits 60 seconds, toggles it back off, waits another 60 seconds, and keeps repeating that cycle.
  • Press Ctrl+C any time to stop it.

That toggle-and-wait cycle is what creates just enough keyboard activity to keep Windows from treating the machine as idle, without leaving Scroll Lock lit up the whole time.

Build it

1. The batch file. Create caffeinate.bat:

@echo off
start powershell -ExecutionPolicy Bypass -File "%~dp0caffeinate.ps1"

This batch file starts PowerShell and runs the PowerShell script located in the same folder as the batch file. The ExecutionPolicy Bypass option applies only to this PowerShell launch. It is useful for a local personal script, but you should not use it for scripts from untrusted sources.

The %~dp0 part is the folder the batch file is in, so the batch file and script can move together without breaking.

2. The PowerShell script. Create caffeinate.ps1 in the same folder:

$host.UI.RawUI.WindowTitle = "Windows Caffeinate - Scroll Lock"
Write-Host "Windows Caffeinate started. Press Ctrl+C to stop."

Add-Type -AssemblyName System.Windows.Forms

while ($true) {
    [System.Windows.Forms.SendKeys]::SendWait("{SCROLLLOCK}")
    Start-Sleep -Seconds 60

    [System.Windows.Forms.SendKeys]::SendWait("{SCROLLLOCK}")
    Start-Sleep -Seconds 60
}

The script loads the System.Windows.Forms assembly so it can use SendKeys, then loops indefinitely: press Scroll Lock, wait 60 seconds, press it again to toggle it back off, wait another 60 seconds, repeat.

Because the toggle and the wait are two separate steps, stopping the script with Ctrl+C at the wrong moment — right after Scroll Lock was turned on, before it's toggled back off — can leave it lit until you press it yourself. There's no cleanup step in this version to catch that case.

Run it

Put both files in the same folder:

WindowsCaffeinate/
  caffeinate.bat
  caffeinate.ps1

Double-click caffeinate.bat. A PowerShell window opens and the script starts running. To stop it, click inside that window and press Ctrl + C.

Notes and limits

This is a personal productivity script, not a system utility — treat it accordingly:

  • Only run it on machines where you're allowed to run scripts, and only with permission if the machine is shared.
  • Managed policies may limit or override this behavior — don't use it to circumvent your organization's security or power-management rules.
  • It's not a substitute for actually configuring Windows power settings correctly; use it for temporary situations, not as a permanent workaround.

For a one-off task, double-clicking the batch file is enough. CPU use while it runs is essentially zero, since the script spends nearly all its time asleep rather than computing, and there's nothing to install or configure — just the two files themselves. Memory use is small but real, since PowerShell has to stay loaded the whole time it runs.

That simplicity comes with trade-offs: a visible console window instead of a quiet tray icon, and the Scroll Lock quirk mentioned earlier. If you find yourself reaching for this often, PowerToys' Awake module is probably the better fit — it likely uses the same kind of low-level Windows API a native app would, so it's lighter and avoids that quirk, at the cost of being an install rather than two text files you can read yourself.


Posted on June 23, 2026 by Desk2Mob in Windows, Caffeinate, powershell, batch file, productivity


All Posts