Skip to content

Instantly share code, notes, and snippets.

@EugeneLoy
Last active June 30, 2024 16:26
Show Gist options
  • Save EugeneLoy/150044d04b08e35d09e164c864e78da7 to your computer and use it in GitHub Desktop.
Save EugeneLoy/150044d04b08e35d09e164c864e78da7 to your computer and use it in GitHub Desktop.
powershell (Add-Type '[DllImport(\"user32.dll\")]^public static extern int PostMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::PostMessage(-1,0x0112,0xF170,2)
@Shazib
Copy link

Shazib commented Jun 3, 2023

FYI I've discovered that this doesn't play nice with my monitor that supports DDC/CI control. https://github.com/xanderfrangos/twinkle-tray/ works though.

@GustavoCOD4
Copy link

Thank you

@Nine-Iron
Copy link

To anyone looking to shut off a specific monitor and have it stay off until you physically push the monitor power button, it looks like there is a utility for it. Can even change settings by command line.

https://www.winhelponline.com/blog/turn-off-monitor-shortcut-command-windows/

Nirsoft’s ControlMyMonitor

@RedSnt
Copy link

RedSnt commented Dec 15, 2023

Brilliant, thanks for this. Windows is a bit weird when you mix and match displayport and HDMI monitors where windows will jump from the DP monitor to the HDMI one when you physically turn the power off both, so this solution with a bat file is preferable - even thought I also use Persistent Windows.

FYI I've discovered that this doesn't play nice with my monitor that supports DDC/CI control. https://github.com/xanderfrangos/twinkle-tray/ works though.

Also, thanks for the recommendation of Twinke-Tray @Shazib.

@KennethWarner
Copy link

I'm having a problem using this powershell script on my Asus MiniPC PB60. It does turn off the monitor. I set it up in Task Scheduler to run when the machine is locked. Works like a charm. Trouble is that it seems to disable background processes, too. I'm using this machine primarily as an iTunes and HomeBridge server. But if I use this script, both HomeBridge and iTunes stop working with the machine locked. It also takes out the little utility that controls the UPS, which is connected by USB. As long as I don't use this script to turn off the monitor, everything works fine with the machine locked.

Any ideas? Is there a way to modify this script to turn the monitor off, but allow everything else to keep running?

@Shazib
Copy link

Shazib commented Jun 22, 2024

I'm having a problem using this powershell script on my Asus MiniPC PB60. It does turn off the monitor. I set it up in Task Scheduler to run when the machine is locked. Works like a charm. Trouble is that it seems to disable background processes, too. I'm using this machine primarily as an iTunes and HomeBridge server. But if I use this script, both HomeBridge and iTunes stop working with the machine locked. It also takes out the little utility that controls the UPS, which is connected by USB. As long as I don't use this script to turn off the monitor, everything works fine with the machine locked.

Any ideas? Is there a way to modify this script to turn the monitor off, but allow everything else to keep running?

It seems like this is an issue with modern standby modes. When you turn the monitor off in this way it puts the entire machine into sleep mode. I'm guessing that this only happens on devices such as laptops.

There is a stack overflow post here discussing it, and offering some recommendations for alternative API's you can call to resolve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment