Code Snippets
Thursday, 1 January 2026, 11:12 AM
Instantly Sleep Your Monitors With a One-Click BAT File (Windows 11)
<p>Want a quick way to turn off your monitors immediately, without putting your PC to sleep? This tiny batch file does exactly that. Your screens will go dark instantly and wake back up the moment you move the mouse or hit a key.</p>
<h3>What this does</h3>
<p>This script sends Windows the “turn off display” command. It does <strong>not</strong>:</p>
<ul><li>
<p>shut down your PC</p>
</li><li>
<p>hibernate</p>
</li><li>
<p>close apps</p>
</li><li>
<p>stop downloads, streams, or music</p>
</li></ul>
<p>It only puts your display(s) to sleep until you interact again.</p>
<p></p><hr><p></p>
<h2>Step 1: Create the batch file</h2>
<ol><li>
<p>Open <strong>Notepad</strong></p>
</li><li>
<p>Paste this code:</p>
</li></ol><pre><code>@echo off
powershell -command "(Add-Type '[DllImport(\"user32.dll\")] public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name Native -Namespace Win32 -PassThru)::SendMessage(0xFFFF,0x112,0xF170,2)"</code></pre><ol><li><p>Click <strong>File -> Save As</strong></p>
</li><li>
<p>Set:</p>
<ul><li>
<p><strong>File name:</strong> <code>SleepMonitors.bat</code></p>
</li><li>
<p><strong>Save as type:</strong> <code>All Files (*.*)</code></p>
</li><li>
<p><strong>Encoding:</strong> <code>UTF-8</code> (optional, but fine)</p>
</li></ul>
</li><li>
<p>Save it somewhere easy like your Desktop.</p>
</li></ol>
<p></p><hr><p></p>
<h2>Step 2: Run it</h2>
<p>Double-click <code>SleepMonitors.bat</code>.</p>
<p>Your screens should go dark immediately.</p>
<p>To wake them:</p>
<ul><li>
<p>move your mouse, or</p>
</li><li>
<p>press any key</p>
</li></ul>
<p></p><hr><p></p>
<h2>Optional: Make it feel like a real “button” (desktop shortcut + icon)</h2>
<h3>Create a shortcut</h3>
<ol><li>
<p>Right-click <code>SleepMonitors.bat</code></p>
</li><li>
<p>Choose <strong>Show more options</strong> (if you’re on Windows 11’s compact menu)</p>
</li><li>
<p>Click <strong>Create shortcut</strong></p>
</li></ol>
<h3>Assign an icon</h3>
<ol><li>
<p>Right-click the shortcut -> <strong>Properties</strong></p>
</li><li>
<p>Click <strong>Change Icon</strong></p>
</li><li>
<p>Browse to a <code>.ico</code> file you like</p>
</li><li>
<p>Apply/OK</p>
</li></ol>
<p></p><hr><p></p>
<h2>Optional: Set a keyboard hotkey</h2>
<ol><li>
<p>Right-click the shortcut -> <strong>Properties</strong></p>
</li><li>
<p>Click into <strong>Shortcut key</strong></p>
</li><li>
<p>Press something like <code>Ctrl + Alt + M</code></p>
</li><li>
<p>Apply</p>
</li></ol>
<p>Now you can sleep the monitors instantly from the keyboard.</p><p>Icon you can use:</p><p></p>
<p></p><hr><p></p>
<h2>Troubleshooting</h2>
<p><strong>Nothing happens</strong></p>
<ul><li>
<p>Make sure you saved it as <code>.bat</code> and not <code>.txt</code></p>
</li><li>
<p>Ensure the file contains both lines exactly, starting with <code>@echo off</code></p>
</li></ul>
<p><strong>PowerShell warning / policy issues</strong><br>
This command runs a one-liner and typically works even on systems with stricter policies, but if yours is locked down, try running PowerShell as admin once, or use a different method (rundll32). Most Windows 11 systems are fine with the above.</p><p>Here is the bat file already done for you.</p><p></p>
Comments 0