Rss Feed

25 May 2009

Lock My Computer Programmatically in C#?

The following code is used to Lock a Computer programmatically. It is nothing but calling a hook on the user32.dll library and commands also exist for shut down, log off, restart...
Process.Start(@"C:\WINDOWS\system32\rundll32.exe",
"user32.dll,LockWorkStation");

Addional information on how to use .NET Process class can be found at MSDN or by following the link below.

Process Class Documentation

1 Comments:

Anonymous Anonymous said...

A much better design that isn't hard coded to your windows system paths, etc:

using System.Runtime.InteropServices;

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

Then just call LockWorkStation();

28 July, 2009 20:45  

Post a Comment

<< Home