How to Make a Simple Caffeinate-Style Application for Windows
On macOS, the caffeinate command is commonly used to keep the system awake during long-running tasks. Developers use it when running scripts, downloads, uploads, builds, backups, or remote sessions that should not be interrupted by system sleep.
Windows does not provide the exact same everyday command in the same simple form, but we can create a lightweight alternative using a batch file and a PowerShell script.
Windows has advanced power configuration tools, but this article focuses on a simple script-based approach that is easy to create, run, and stop.
The idea is simple: send a harmless key press at a regular interval so Windows does not treat the machine as completely idle. In this example, we use the Scroll Lock key because it usually has very little impact on normal work.
Use Case
- Running a long script
- Downloading or uploading large files
- Watching a dashboard
- Keeping a remote session active
- Preventing the screen from sleeping during a temporary task
- Keeping a development process visible while monitoring logs
How the Solution Works
User starts batch file
|
v
Batch file starts PowerShell
|
v
PowerShell sends Scroll Lock
|
v
Waits for 60 seconds
|
v
Sends Scroll Lock again
|
v
Repeats until stopped
The script turns Scroll Lock on and then turns it back off. This avoids leaving Scroll Lock permanently enabled while still creating light keyboard activity.
Step 1: Create the Batch File
Create a file named scrolllock.bat.
scrolllock.bat
Add the following content:
@echo off
start powershell -ExecutionPolicy Bypass -File "%~dp0scrolllock.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 means the directory where the batch file is located. This allows the batch file and PowerShell script to work together even if you move them to another folder.
Step 2: Create the PowerShell Script
Create another file in the same folder named scrolllock.ps1.
scrolllock.ps1
Add the following content:
$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
}
How It Works
The script loads the System.Windows.Forms assembly so it can use SendKeys. Then it enters an infinite loop.
- The first Scroll Lock key press turns Scroll Lock on.
- The script waits 60 seconds.
- The second Scroll Lock key press turns Scroll Lock off.
- The script waits another 60 seconds.
- The loop repeats until the user stops it.
This creates small keyboard activity without typing into documents or changing application content.
How to Run It
Put both files in the same folder.
scrolllock.bat
scrolllock.ps1
Double-click the batch file:
scrolllock.bat
A PowerShell window will open and the script will start running.
To stop it, click inside the PowerShell window and press Ctrl+C.
Ctrl + C
Folder Structure
WindowsCaffeinate
|
v
scrolllock.bat
scrolllock.ps1
Important Notes
- This is a simple personal productivity script.
- Use it only on machines where you are allowed to run scripts.
- This does not replace proper Windows power settings.
- This may not override company-managed sleep, lock screen, or security policies.
- If your organization has device management rules, follow those rules first.
When Not to Use This
- Do not use it to bypass required security lock policies.
- Do not use it on shared machines without permission.
- Do not use it as a permanent replacement for correct power configuration.
- Do not run it forever without understanding why it is needed.
Final Thought
This is a lightweight Windows version of the macOS caffeinate idea. It is not a full system utility, but it is simple, practical, and easy to understand.
For temporary tasks such as long downloads, uploads, scripts, builds, or monitoring sessions, this small batch and PowerShell combination can be a useful tool.

