Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I lock a windows workstation programmatically? [duplicate]

Tags:

c#

user32

Possible Duplicate:
Lock Windows workstation programmatically in C#

I am currently working on a visual studio windows form application that requires a function that locks the workstation. How can i make use of user32.dll to do a lock (Windows + L) when the function is called?

like image 690
Derek Avatar asked Dec 06 '12 14:12

Derek


1 Answers

I haven't tried it myself, but I found this on google

Process.Start(@"C:\WINDOWS\system32\rundll32.exe", "user32.dll,LockWorkStation");

edit: I tried it, and it works!

edit2: Here's a solution using user32.dll that doesn't start an external process.

using System.Runtime.InteropServices;

declare a method like this:

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

and then call LockWorkStation();.

Voilà

like image 172
Pacane Avatar answered Oct 03 '22 04:10

Pacane