Created
March 3, 2025 08:20
-
-
Save ph33nx/395e8c5a64a42dae593091fc491875f1 to your computer and use it in GitHub Desktop.
PowerShell Windows API Script: Instantly Turn Off Your Monitor (Developer Hack) Leverage this advanced PowerShell script that uses Windows API calls to instantly power off your monitor without disrupting background tasks. Perfect for system automation, IT efficiency, and developer productivity. Follow the included shortcut instructions to set up…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TurnOffMonitor.ps1 | |
# This script leverages the Windows API via .NET to power off the display while keeping background processes running. | |
# Author: ph33nx (https://github.com/ph33nx) | |
# Shortcut Instructions: | |
# 1. Right-click on your Desktop and select "New > Shortcut". | |
# 2. In the "Type the location of the item" field, paste: | |
# powershell.exe -ExecutionPolicy Bypass -File "C:\path\to\TurnOffMonitor.ps1" | |
# 3. Click "Next", give your shortcut a name (e.g., "Turn Off Monitor"), and finish. | |
# 4. (Optional) Assign a hotkey by right-clicking the shortcut, selecting "Properties", and setting your desired key combination. | |
# Keywords: Windows API, PowerShell, monitor off, turn off display, display sleep shortcut, Windows shortcut, system automation, | |
# senior developer script, IT automation, tech hack, power management, developer tools, Windows programming. | |
# Add a .NET type with the Windows API function | |
Add-Type -TypeDefinition @" | |
using System; | |
using System.Runtime.InteropServices; | |
public class MonitorControl { | |
[DllImport("user32.dll", CharSet = CharSet.Auto)] | |
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); | |
} | |
"@ | |
# Define the constants | |
$HWND_BROADCAST = [IntPtr]::new(0xFFFF) | |
$WM_SYSCOMMAND = 0x0112 | |
$SC_MONITORPOWER = 0xF170 | |
# '2' tells the monitor to power off | |
[MonitorControl]::SendMessage($HWND_BROADCAST, $WM_SYSCOMMAND, $SC_MONITORPOWER, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can be edited to support multiscreen setup? , i want to turn off specific screen not all of them