RSS

Lock Workstation through Code , Locking Workstation


Reposting from prev blog

Idle mind is Devils Workshop!!

Today didnt have much tasks to work on as had already finished the task expected to go on till today evening ,hence had loads of free time to try out stuff
Found this link Lockworkstation Function and thouht of implementing it in .NET since I hated the idea of

CTRL + ALT + DEL and ENTER / Win + L to lock my workstation.

Anyways here it is the code

You will need to include the Namespace
using System.Runtime.InteropServices;

Copy the following in the Code behind



[DllImport("user32.dll")]

public static extern void LockWorkStation();

And in the form load event give a call to the LockWorkStation Method we declared above.

private void LockStation_Load(object sender, System.EventArgs e)
{
try

{
LockWorkStation();
}
finally
{
this
.Close();
}
}


Thats it you are done !! Copy the Assembly from the bin folder onto your desktop and click on it whenever you want to Lock your workstation!!

Cheers!!

Post a Comment

Copyright © Shounak S. Pandit. Powered by Blogger.

Ads