Shortcut to turn off monitors on Windows 10

Shortcut to turn off monitors on Windows 10

·

3 min read

My computer is in the lounge and it tends to be left on for most of the day (especially with WFH in full effect). With 4 monitors hooked up, it actually outputs a decent amount of light and if you're trying to watch a movie on the TV it can be distracting.

Of course, I could just turn off the PC or adjust the power settings so that the monitors turn off quickly. However, that doesn't really work for me as a) the PC is usually doing something in the background b) I don't want to have to keep adjusting power settings to suit the time of day/use case.

So what can be done? Well, turns out that you can execute the SendMessage method in the user32.dll Windows API with something like:

# Import: user32.dll
# Method:
# SendMessage(HWND_BROADCAST,WM_SYSCOMMAND, SC_MONITORPOWER, POWER_OFF)
# Parameters:
# HWND_BROADCAST  0xffff
# WM_SYSCOMMAND   0x0112
# SC_MONITORPOWER 0xf170
# POWER_OFF       0x0002

# Example call to turn off all monitors
SendMessage(0xffff, 0x0112, 0xf170, 0x0002)

Seems simple enough, of course, there are few ways to go about executing it. You could build a basic console app in C# or even write a PowerShell script.

What I wanted was a simple way to trigger a turn off of all my monitors either via a keyboard shortcut or system tray icon.

Turn off monitors via PowerShell

In PowerShell, you can just import the user32.dll and call the SendMessage method, like so:

function Disable-Display {
    $Signature = @"
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
"@

    $HideMonitor = Add-Type -MemberDefinition $Signature -Name "Win32HideMonitor" -PassThru
    $HideMonitor::SendMessage(0xffff, 0x0112, 0xF170, 2)
}

Disable-Display

Nothing much to it and I could then use something like AutoHotkey to run the script whenever I pressed a combination of keys.

Display Power Off Utility

After doing a bit of research, I came across the Display Power Off Utility developed by i2van.

It's a simple Windows desktop app written in C++ (source code available here) that sits in your system tray and by double-clicking the icon, it will immediately turn off all your monitors!

Display Power Off Utility - System tray icon

Amazing, no point me building anything as this fits the bill exactly!

Run on log on

By default, the app only runs when you execute the doff-tray.bat script. That will in turn run the doff.exe application and display the app in your system tray. If you want it to always run when you log on to your machine then the easiest way to accomplish that is by creating a scheduled task.

  1. Open Task Scheduler
  2. Press Create Basic Task...
  3. For Name, enter something descriptive like "Run Display Power Off Utility"
  4. Press Next, select When I log on, press Next
  5. Select Start a program, press Next
  6. Press Browse... and navigate to the app folder and select the doff-tray.bat file, press Open then Next
  7. Press Finish to save the task.

Now, every time you log on the app will run and you can turn off all your monitors by just double-clicking a system tray icon!