Call the LockWorkStation function using PInvoke.
The following code can be used to Lock a Computer programmatically.
using System.Runtime.InteropServices;[DllImport("user32.dll")]public static extern void LockWorkStation();