|
#1
|
|||
|
|||
Monitor off
I needed something fast to turn off laptop screen.
I come across this one line command, can use it as a shortcut or a batch file. Tested on a windows 10 laptop work fine so far. Attached contain the shortcut file and also the batch file. Credit to whoever posted online(I forgot where I find it). |
#2
|
|||
|
|||
For those who are curious about the batch file or the command, here it is:
Code:
cmd /c "powershell.exe -Command "(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)"" Here is a short explanation of the code: The SendMessage function is imported from the User32.dll library. The function is called with the following parameter codes 0x0112 and 0xF170,2. They are: WM_SYSCOMMAND (0x0112) which is sending messages to the Windows System Command to the windows application and 0xF170 is the type of System command SC_MONITORPOWER in this case. Code:
SC_MONITORPOWER 0xF170 Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer. The lParam parameter can have the following values: -1 (the display is powering on) 1 (the display is going to low power) 2 (the display is being shut off) Code:
hxxps://learn.microsoft.com/en-us/windows/win32/menurc/wm-syscommand |
The Following User Gave Reputation+1 to foosaa For This Useful Post: | ||
blue_devil (11-15-2023) |
The Following 5 Users Say Thank You to foosaa For This Useful Post: | ||
darkBLACK (11-19-2023), MarcElBichon (11-17-2023), Mendax47 (11-19-2023), tonyweb (11-19-2023), wild (11-17-2023) |
#3
|
|||
|
|||
How to turn it back on?
|
#4
|
|||
|
|||
#5
|
|||
|
|||
I suggest to use the asynchronous PostMessage(...) instead of the synchronous SendMessage(...) to avoid waiting forever.....
Code:
cmd /c "powershell.exe -Command "(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)"" |
The Following User Gave Reputation+1 to wild For This Useful Post: | ||
Fyyre (12-07-2023) |
The Following 4 Users Say Thank You to wild For This Useful Post: | ||
blue_devil (11-19-2023), foosaa (05-03-2024), niculaita (11-30-2023), tonyweb (11-19-2023) |
Thread Tools | |
Display Modes | |
|
|