Skip to Content
The .NET Developer's Guide to Windows Security
book

The .NET Developer's Guide to Windows Security

by Keith Brown
September 2004
Intermediate to advanced
408 pages
7h 25m
English
Addison-Wesley Professional
Content preview from The .NET Developer's Guide to Windows Security

Chapter 72. How to Programmatically Lock the Console

Have you ever configured your screensaver to require a password or, on Windows XP, to “show the Welcome screen”? I've seen some special-purpose programs that need to implement similar behavior: locking the interactive console under certain conditions. It's easy to do, so I've included it here. The function you need to call is in Win32, and it's called LockWorkstation. Here's a C# program that locks the console when run:

using System.Runtime.InteropServices;

class LockItUp {
  static void Main() {
    LockWorkStation();
  }
  [DllImport("user32.dll")]
  static extern void LockWorkStation();
}

After this program runs, the default desktop will be hidden and the Winlogon desktop will be displayed. All programs ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

.NET Framework Security

.NET Framework Security

Brian A. LaMacchia, Sebastian Lange, Matthew Lyons, Rudi Martin, Kevin T. Price
Programming .NET Security

Programming .NET Security

Adam Freeman, Allen Jones

Publisher Resources

ISBN: 0321228359Purchase book