Wednesday, August 18, 2010

Lock the Computer

In a previous post I explained, how to shutdown the computer using C# or to log out a user. Today I want to show you, how to lock the computer with C# (which can be achieved with Ctrl + Alt + Del - Lock Computer or Win + L).
This action can be done with an API function. As always, to include such a we need the following using directive:

using System.Runtime.InteropServices;

With the following code the needed function then is included:

[DllImport("user32.dll")]
public static extern bool LockWorkStation();

LockWorkStation() now can be called anytime, locking the computer.

No comments:

Post a Comment