Exetools

Exetools (https://forum.exetools.com/index.php)
-   Source Code (https://forum.exetools.com/forumdisplay.php?f=46)
-   -   Monitor off (https://forum.exetools.com/showthread.php?t=20534)

Max 05-13-2023 02:51

Monitor off
 
1 Attachment(s)
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).:p

foosaa 11-15-2023 14:15

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)""
Create a batch file with the above command line and assign as shortcut key to it in the batch file's properties for easier use or just execute the batch file by clicking as an icon in your taskbar. Either ways, it just switches off the monitor and locks the screen.

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)

If one would to know more, refer to the following MSDN page:

Code:

hxxps://learn.microsoft.com/en-us/windows/win32/menurc/wm-syscommand
Hope it helps to know a thing or two about calling the APIs directly from command line using PowerShell.

chants 11-17-2023 07:54

How to turn it back on?

fqjp 11-17-2023 12:01

Quote:

Originally Posted by chants (Post 129278)
How to turn it back on?

Wake up with a mouse or keyboard click

wild 11-17-2023 21:15

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)""


All times are GMT +8. The time now is 18:45.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX