11

You can lock a Windows PC by pressing Windows + L.

How can I lock a Windows PC using VB.NET or C#?

A short example would be helpful.

Charles
  • 50,943
  • 13
  • 104
  • 142
Augis
  • 1,903
  • 1
  • 16
  • 21
  • [Related question](http://stackoverflow.com/questions/4259571/how-to-lock-the-screen-in-windows) in C/C++ – Deanna Aug 06 '12 at 10:36

2 Answers2

11

Call the LockWorkStation function using PInvoke.

usr
  • 168,620
  • 35
  • 240
  • 369
7

The following code can be used to Lock a Computer programmatically.

using System.Runtime.InteropServices;

[DllImport("user32.dll")]
public static extern void LockWorkStation();
Jainendra
  • 24,713
  • 30
  • 122
  • 169