Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Putting together <a href="https://stackoverflow.com/questions/1430108/1433591#1433591">the <code>cmd</code> and <code>vbs</code> script ideas</a> with the code from <a href="https://stackoverflow.com/questions/267728/267735#267735">the answer to Launch System Screensaver from C# Windows Form</a> I came up with the following:</p> <pre><code>using System; using System.Runtime.InteropServices; public static class LockDesktop { [DllImport("user32.dll", EntryPoint = "GetDesktopWindow")] private static extern IntPtr GetDesktopWindow(); [DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam); [DllImport("user32.dll", EntryPoint = "LockWorkStation")] private static extern IntPtr LockWorkStation(); private const int SC_SCREENSAVE = 0xF140; private const int WM_SYSCOMMAND = 0x0112; public static void SetScreenSaverRunning() { SendMessage(GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0); LockWorkStation(); } public static void Main() { LockDesktop.SetScreenSaverRunning(); } } </code></pre> <p>To build it, <a href="http://smallestdotnet.com/" rel="nofollow noreferrer">install the .NET Framework</a>, copy and paste the above code into <code>lock.cs</code>, then run:</p> <pre><code>%SystemRoot%\Microsoft.NET\Framework\v3.5\csc.exe lock.cs </code></pre> <p>Put the created <code>lock.exe</code> in your path, after that, typing <code>lock</code> should engage the configured screen saver and lock your workstation.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload