Date

I recently upgraded my trusty ThinkPad T42 to Windows 7. Unfortunately, the screen-off keystroke no longer works. Some quick Googling showed that people made their [own handlers in C#][]. Well, that sucks if you don't have the .net CLR. This is not a problem on Windows 7, but I also wanted to try out my Assembly skills since they were all just calling standard Win32 APIs.

Download LCDOff.exe

This should work on fairly old systems, back to Windows NT 3.1 and Windows 95, unlike the C# versions. It is also 7.5kb vs 85kb.

I wrote it in MASM using the Irvine library for convenience. Optimized with http://upx.sourceforge.net/

TITLE Monitor Off (main.asm)  
; Description: This program turns off your monitor (power saving mode)  
; Revision date: 2 November 2009

INCLUDE Irvine32.inc  
INCLUDELIB Kernel32.lib  
INCLUDELIB User32.lib

SendMessageA PROTO :DWORD,:DWORD,:DWORD,:DWORD  
GetConsoleWindow PROTO

WM\_SYSCOMMAND = 0112h  
SC\_MONITORPOWER = 0F170h  
OFF = 2

.data  
msg BYTE "Monitor off. Program from Kev009.com",0dh,0ah,0

.code  
main PROC

call Clrscr

; Get our window handle to send the event to  
INVOKE GetConsoleWindow  
; The handle is now in eax  
INVOKE SendMessageA, eax, WM\_SYSCOMMAND, SC\_MONITORPOWER, OFF

mov edx,OFFSET msg  
call WriteString

exit  
main ENDP  
END main  

I've set up a project page at if there ever need to be updates.


Comments

comments powered by Disqus