by Vitaly Zayko
13. January 2009 15:48
There is no such .NET function (or at least I didn’t find). Fortunately we can use PInvoke instead.
Use this function to lock workstation’s display to protect from unauthorized use. Result of this function is the same as pressing Ctrl+Alt+Del.
- Add namespace at the top of your code:
using System.Runtime.InteropServices;
- Declare PInvoke:
[DllImport("user32.dll", SetLastError = true)]
static extern bool LockWorkStation();
- Call this function like this:
if (!LockWorkStation())
throw new Win32Exception(Marshal.GetLastWin32Error());