I apologize for grave digging, but this page comes as a top search result for triggering a screensaver with a shortcut key. I thought it'd be useful to add another, updated method for doing something that few people seem to know how to do.
Note: This is a solution made for and tested on Windows 8 but should also work for Windows 7. There is a better solution for older OSes, however; check here: http://stackoverflow.com/questions/1430108/how-to-turn-screensaver-on-windows-7-by-a-code-in-cmd.
First, create a folder. Then, find a cmd.exe and copy it to the folder. Now, create a text file (don't worry about naming it yet) and paste the following code into it:
public static class LockDesktop
[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
private static extern IntPtr GetDesktopWindow();
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
private const int SC_SCREENSAVE = 0xF140;
private const int WM_SYSCOMMAND = 0x0112;
public static void SetScreenSaverRunning()
SendMessage(GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0);
public static void Main()
Now, click "save as" and set the file type to "all" before saving the file as "lock.cs". Make sure to save it to the folder you created. Finally, open the CMD.exe from the folder and type in the following command:
Press Enter and wait a moment. You'll now find a "lock.exe" file in your folder. You can create a shortcut (send to desktop) to it and go to properties to assign a keyboard shortcut.
**Note: This will simply launch your set screensaver as if the timer ran out. If you do not have it set to display logon screen at resume, it will not lock. There is also a delay of about five seconds before it locks since this is the default behavior of screensaver so that the user has time to cancel it from locking.
If you do not want to set your screen saver to lock on resume and/or want you computer to lock instantly with the shortcut, continue reading.**
Create another text file or use the old one, it doesn't matter. Now, enter the following batch code and save it as "lock.bat".
Now you can create a shortcut once again and give it a keyboard command.