Turn off display in Windows on command
Solution 1
On a laptop you can use the keyboard shortcut combination of Fn+F7 (F7 might differ depending on the laptop model) and for a desktop you can always use the power button.
Do you need any other specifications such as wake up on mouse movement or something else?
You can always create a shortcut and assign a keyboard shortcut to a black screensaver, use this path:
%systemroot%\system32\scrnsave.scr /s
This will not turn off you screen but make it completely black
Solution 2
A couple more options:
- Turn Off LCD - just place the executable on your desktop
-
NirCmd - you'll need to copy nircmd.exe to your Windows system directory, or add its location to the PATH environment variable. Then just run
nircmd monitor off
from the command line. More information at the link.
Solution 3
You can use WinAPI call SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2)
where HWND_BROADCAST = 0xFFFF
,
WM_SYSCOMMAND = 0x0112
and SC_MONITORPOWER = 0xF170
. The 2
means the display is being shut off.
There are several ways to make the call:
Separate executable. You can fire it through a script, command line, Run window, shortcut (
*.lnk
), etc. Note that shortcuts can be invoked using a keyboard shortcut. The executable may be written in C or C++, or via P/Invoke in .NET languages (C# or PowerShell), or in many other languages that have a foreign language interface (e.g. JNI in Java).-
AutoHotkey script. For a non-programmer, this way is probably simpler. Making customizations still requires some scripting. This script turns monitor off on Win + M:
#m:: Sleep 1000 SendMessage, 0x112, 0xF170, 2,, Program Manager return
Note the timeout before the SendMessage
call in the AutoHotkey script. It gives the user a chance to release keys (in case their release would wake up the monitor again). Do not forget about it even when making the call from a script in another language.
For more info, see the documentation of SendMessage
function, WM_SYSCOMMAND
message and AutoHotkey SendMessage
. It might be of interest that since Windows 8, using the same method to turn monitor on does not work, but there is a work-around.
Solution 4
Powershell one-liner would be:
(Add-Type -MemberDefinition "[DllImport(""user32.dll"")]`npublic static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);" -Name "Win32SendMessage" -Namespace Win32Functions -PassThru)::SendMessage(0xffff, 0x0112, 0xF170, 2)
Related videos on Youtube
unicoio
Updated on September 18, 2022Comments
-
unicoio over 1 year
Is there a way to turn off the display in Windows (7), preferably without using additional software?
Powershell script works fine, but leaves command-line window after turning on the display.
-
Admin almost 13 yearsYou have an existing ps1 script? They don't usually leave the window open after running. Perhaps there's something in the script that needs to be changed to let the window close?
-
Admin over 11 yearsalso if you may paste the ps script here - it will be useful for us visitors
-
Admin almost 3 yearsPut PowerShell command from below answers in a file, save as .ps1, chose default app to open with as powershell, create a shortcut for it, go to the properties of the shortcut and set up a key combination to trigger it. this key combination will work from anywere.
-
Admin almost 3 yearsmight have to place the shortcut in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories for the shortcut keystore to work.
-
-
unicoio almost 13 yearsI have desktop and as far as I know it is not possible to set power button to turn off display. Wake up on mouse movement or keyboard key is fine. Black screensaver leaves glow, which is visible at night.
-
Greg almost 13 years@unicoio If it's to turn off the screen for the whole night why don't you use the power button on the screen itself?
-
Motes about 10 yearsI arrived at this question over three whole steps, literal strides. Your screensaver answer was exactly what I needed. My LCD TV treats solid complete black as off.
-
LMSingh almost 10 years+1 for launching scrnsave.scr. This doesn't kick in the actual power save, so I can attach it to a hotkey and turn the laptop monitor off while lid remains open.
-
Smit Johnth about 9 years+1 for
nircmd
. Imho tools set from Nir Sofer and Russinovich should be installed on any advanced user's PC. -
Andrey Dmitriev over 7 yearsWhat's
/s
for, it works without the switch as well. -
Marcin Orlowski over 7 years@Chinggis6 no, it does not (or it might, but it should not really). As microsoft's docs say
/s
stands for "Run the Screen Saver now", while launching w/o any switch means "Show the Settings dialog box" -
Luigi over 7 yearsI have tools from Russinovich but this is the first time I've heart of Nir Sofer. Looks cool
-
Palec almost 7 yearsIn Windows 10, screen gets black when
scrnsave.scr
is entered in the search box or in run dialog, but it requires/s
when executed fromcmd.exe
(without it, a dialog pops up informing that this screensaver has no configurable options). -
Cerlancism almost 4 yearsnircmd and Turn off LCD will somehow turn back screen on after exactly 5mins on Windows 10.
-
cyqsimon almost 4 yearsFor the AutoHotkey method, I would recommend using a
Sleep 50
afterSendMessage
instead of this long sleep before. This has the effect of turning off the screen immediately. Tested on my own laptop and found it to be better. -
Kidquick over 3 yearsThis was close, but didn't work for me (Win10). However I put this into a .bat file and it worked:
powershell (Add-Type '[DllImport(\"user32.dll\")]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)
-
Jari Turkia over 3 yearsWell adapted! I'm a PowerShell user and would run from a
.ps1
-file. Running unsigned PowerShell-scripts isn't enabled by default, so your solution will work for all. -
JPX over 3 yearsThis does not work on my Windows 10 20H2 computer. The one-liner will hibernate the entire computer. Same problem with NirCMD. The one-liner and NirCMD work on Windows 7 computer.
-
Jari Turkia over 3 yearsOn my Win10 20H2 running above single-liner in PowerShell Core 7.1 does turn off display as it did in previous versions. It does not hibernate my computer.
-
JPX over 3 yearsI tested the single-liner and NirCMD in two Lenovo ThinkCentre M90N-1 computers which will hibernate. Windows turns off the monitor without hibernation. If I try to turn the display on by running a command
nircmd monitor on
, monitor will turn on for a second and then the computer will hibernate. -
Jari Turkia over 3 yearsI've tested the PowerShell single-liner on couple of my computers. Working as as expected. Given you're the first one to report computer hibernation, I'd have to assume this is a Lenovo-issue.
-
CeePlusPlus over 3 yearsThis is Kidquick's script in raw powershell:
(Add-Type "[DllImport(""user32.dll"")]`npublic static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);" -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)
-
Jari Turkia over 3 years@CeePlusPlus Kidquick's script is exactly the same when compensated for missing names for arguments and -1 vs 0xffff.
-
CeePlusPlus over 3 yearsI hear, its not immediately clear with
MemberDefinition
and-Namespace Win32Functions -PassThru
. I'm looking to turn off 1 monitor of 3 if you have any suggestion by the way superuser.com/questions/1625092/… -
pglpm over 3 yearsThis solution is nice, but it has the drawback of also stopping any music player (tested with Potplayer and VLC), at least on my Thinkpad Yoga. It seems the command induces a general low-power state (though not hibernation in my case) rather than just turning off the monitor.
-
Jari Turkia about 3 yearsSomething similar to hibernate or music stopping, on a HP Z-book laptop I tested, running the one-liner will enable screen lock. When displays are turned on, a login is required.
-
8HoLoN over 2 yearsI confirm, on a laptop Asus Rog it also turn off the display but also stop any current network activities... so it doesn't only affect the screen, but more turn the pc in power saving mode... (if there is any news about this subject I would be interested :) )
-
8HoLoN over 2 yearsThe same result occurs on an Acer swift 7 pro (network disabled). So it's not brand related.