All Things WinBatch > WinBatch

Tiny tweak to old tech article

(1/3) > >>

The code to turn off the monitor in the article below works, but hangs.
change "SendMessageA" to "PostMessageA" fixes it.

It might seem like an insignificant thing, but it took me a couple hours to figure out, so...


The reason it hangs is that you are sending a broadcast message to all processes with a GUI interface. One of those processes is however not listening. Since SendMessage is synchronous, it hangs waiting for the process to respond. I would recommend finding a better way to hibernate a monitor as this method is not always reliable even using PostMessage.

Gotcha.  interesting.

I also saw this similar code, which is for autohotkey:

--- Quote ---; Turn Monitor Off:  0x0112 is WM_SYSCOMMAND, 0xF170 is SC_MONITORPOWER.
PostMessage, 0x0112, 0xF170, 2,, Program Manager
--- End quote ---

I see that it sends the message directly to wintitle "Program Manager", maybe that is more correct?
So maybe the winbatch code could be like this?

--- Code: Winbatch ---AddExtender("wwctl44i.dll",0,"wwctl64i.dll")
pmwnd=DllHwnd("Program Manager")
;0x0112 is WM_SYSCOMMAND, 0xF170 is SC_MONITORPOWER, 2 is OFF
This seems to work well, at least in initial testing.

And just to beat this obscure horse a little more, I did find another way.
There is a utility called ControlMyMonitor from
It has a command /TurnOff and a bunch more.

Neither of your posted scripts using PostMessage works on my Windows 11 system and neither works nor hangs using SendMessage either. I suspect but do not know that the not working part has more to do with the installed device drivers than the OS version. That said there are multiple reports of the SC_MONITORPOWER not working on Windows 8.1 and newer systems on various Websites.


[0] Message Index

[#] Next page

Go to full version