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.