Thursday, June 12, 2008

Are you lazy?? Then this one is for you !!

Are you so lazy enough that you need a short cut for locking your system. The contemporary way is to press Ctrl+Alt+Del and choose "lock computer" or more simpler "Win key + L". Well now I am saying a more simpler one ;)
Double click an executable on your desktop and you are done.

I tried to upload an exe for you all but alas..blogger stopped me from uploading..So life is not so easy..But can invest some time now and be lazy later, right? So, i can tell you the steps to get your exe done.. The whole magic is done by just a single Windows API "LockWorkStation() ". So if you know about this already, then you already know this stuff!!

For those who still think they want to know..Here we go!
1. Firstly create a Win32 application.
2. In the InitInstance, call LockWorkStation()
3. Call PostQuitMessage() to exit your application. That should do.

Double click your executable and your system is locked..

Code snippet:
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,

if (!hWnd)
return FALSE;

//I dont want any window to be seen by the user, so commenting it out
//ShowWindow(hWnd, nCmdShow);

//Lock your workstation

//Quit your application

return TRUE;

LockWorkStation() is defined in winuser.h and needs user32.lib library.
For details:

Ok so thats all for today!