Show Changes Show Changes
Edit Edit
Print Print
Recent Changes Recent Changes
Subscriptions Subscriptions
Lost and Found Lost and Found
Find References Find References
Rename Rename
Search

History

7/31/2004 9:10:58 AM
List all versions List all versions
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 will continue to run as normal, and the interactive user will still be logged on. However, she'll have to re-enter her password to get back to her desktop.

PortedBy KeithBrown

PluralsightTraining

Keith's first book-in-a-wiki. If you would like to read the book online or order a physical copy to throw at annoying coworkers, surf to the HomePage. Please note that due to overwhelming wikispam, this particular wiki is no longer editable.

About FlexWiki.

Recent Topics