Skip to content

Instantly share code, notes, and snippets.

@yallie
Forked from EugeneLoy/Turn off Screen.bat
Last active April 1, 2023 22:58
Show Gist options
  • Save yallie/019c5d9e527251e96d8ffff167f2523b to your computer and use it in GitHub Desktop.
Save yallie/019c5d9e527251e96d8ffff167f2523b to your computer and use it in GitHub Desktop.
Turns off the screen and locks the workstation
@echo off
:: see https://www.makeuseof.com/tag/3-quickest-ways-turn-computer-screen-windows/
:: see https://gist.github.com/EugeneLoy/150044d04b08e35d09e164c864e78da7
powershell (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)
:: see https://www.pcreview.co.uk/threads/create-a-batch-file-to-lock-computer.3747748/post-12994020
Rundll32.exe User32.dll,LockWorkStation
@yallie
Copy link
Author

yallie commented Apr 1, 2023

Place this batch file on your Windows desktop. Tested on Windows 11.

To enable a hotkey, create a shortcut for the batch file, set an option to start minimized and set a decent hotkey, for example, Ctrl+Alt+Shift+L.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment