I offer the next solution:
Create a .bat file with the next content:
for /f "tokens=3" %%a in ('reg query "hkey_current_user\control panel\desktop" /v scrnsave.exe') do start "" /wait /d "%%~dpa" "%%~nxa" /s
tsdiscon
And launch it when you want to lock the session.
Explanation.
I wanted to do smth described in the title, but didn't find a way to do it (I hope, yet). Therefore I decided to follow the way from the screensaver settings: to lock session as continuation of the screensaver.
The screensaver settings
The script takes a key value for the screensaver from the windows registry and use it to start a pre-configured screensaver. That's why it works only after configuring a screensaver in Windows. You can configure screensaver settings here (press Win+R, enter text below and press OK):
control.exe desk.cpl,screensaver,@screensaver
Also:
You can reach the screensaver settings via GUI.
You can use "rundll32 user32.dll,LockWorkStation" instead of "tsdiscon", but I prefer the second way.
I have an idea to hide all windows before launching a screensaver to prevent reading information during switching to the lock screen.
You can try to find 3rd party app =)
I wanted to find info how to do the same from cmd, but when I didn't find necessary information I decided to join information from the next resources:
Similar question on StackOverflow
Configure screensaver via cmd
and, of course, for /?, reg /? etc. =)
2Win+L to lock the screen? – ejbytes – 2016-06-08T07:12:15.687