Exetools  

Go Back   Exetools > General > Source Code

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 05-13-2023, 02:51
Max Max is offline
Family
 
Join Date: Nov 2013
Posts: 90
Rept. Given: 28
Rept. Rcvd 50 Times in 23 Posts
Thanks Given: 54
Thanks Rcvd at 31 Times in 19 Posts
Max Reputation: 50
Talking 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).
Attached Files
File Type: rar monitor off.rar (1.3 KB, 19 views)
Reply With Quote
The Following 3 Users Say Thank You to Max For This Useful Post:
foosaa (11-15-2023), niculaita (05-13-2023), tonyweb (11-19-2023)
  #2  
Old 11-15-2023, 14:15
foosaa foosaa is offline
Friend
 
Join Date: Dec 2005
Posts: 106
Rept. Given: 36
Rept. Rcvd 13 Times in 11 Posts
Thanks Given: 163
Thanks Rcvd at 84 Times in 32 Posts
foosaa Reputation: 14
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.
Reply With Quote
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  
Old 11-17-2023, 07:54
chants chants is online now
VIP
 
Join Date: Jul 2016
Posts: 737
Rept. Given: 37
Rept. Rcvd 48 Times in 30 Posts
Thanks Given: 671
Thanks Rcvd at 1,064 Times in 482 Posts
chants Reputation: 48
How to turn it back on?
Reply With Quote
  #4  
Old 11-17-2023, 12:01
fqjp fqjp is offline
Friend
 
Join Date: Apr 2011
Posts: 43
Rept. Given: 1
Rept. Rcvd 2 Times in 1 Post
Thanks Given: 2
Thanks Rcvd at 34 Times in 18 Posts
fqjp Reputation: 2
Quote:
Originally Posted by chants View Post
How to turn it back on?
Wake up with a mouse or keyboard click
Reply With Quote
  #5  
Old 11-17-2023, 21:15
wild wild is offline
Friend
 
Join Date: Oct 2017
Posts: 27
Rept. Given: 0
Rept. Rcvd 1 Time in 1 Post
Thanks Given: 46
Thanks Rcvd at 24 Times in 14 Posts
wild Reputation: 1
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)""
Reply With Quote
The Following User Gave Reputation+1 to wild For This Useful Post:
Fyyre (12-07-2023)
The Following 3 Users Say Thank You to wild For This Useful Post:
blue_devil (11-19-2023), niculaita (11-30-2023), tonyweb (11-19-2023)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On



All times are GMT +8. The time now is 04:10.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2024 )