Click here to Skip to main content
13,406,949 members (52,750 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 6 Jun 2005

Lock workstation

, 6 Jun 2005
Rate this:
Please Sign up or sign in to vote.
Lock workstation without downloading the Platform SDK.


The LockWorkStation function submits a request to lock the workstation's display. Locking a workstation protects it from unauthorized use.

Code explanation

The following example locks the workstation using the LockWorkStation function. The function requires version Windows 2000 Professional or later.

This example also illustrates load-time dynamic linking. If the DLL is not available, the application using load-time dynamic linking must simply terminate. The run-time dynamic linking example, however, can respond to the error. This is a good way to prevent forced termination. You can use this technique in the applications which should be runnable at all Windows platforms but with delimited functionality following the currently running version of the system.

#include <windows.h>

#define IsWin2000Plus() ((DWORD)(LOBYTE(LOWORD(GetVersion()))) >= 5)

int (__stdcall * MyLockWorkStation)();

int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                                     LPSTR lpCmdLine, int nCmdShow)
    HINSTANCE hinstLib;

    if (IsWin2000Plus())
        hinstLib = LoadLibrary("USER32.DLL");

        if (hinstLib)
            MyLockWorkStation = (int (__stdcall *)()) 
                  GetProcAddress(hinstLib, "LockWorkStation");

            if (MyLockWorkStation != NULL)
                (MyLockWorkStation) ();

        MessageBox(NULL, "This application requires" 
           " Windows 2000 Professional or higher!", 
           "Lock Workstation", MB_OK);

    return 0;

This application has the same result as pressing Ctrl+Alt+Del and clicking Lock Workstation.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Dalibor Drzik
Web Developer
Slovakia Slovakia
Wink | ;-)

You may also be interested in...

Comments and Discussions

GeneralAlso known as.. Pin
Alexander M.6-Jun-05 11:22
memberAlexander M.6-Jun-05 11:22 
GeneralRe: Also known as.. Pin
Dalibor Drzik7-Jun-05 3:37
memberDalibor Drzik7-Jun-05 3:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180221.1 | Last Updated 6 Jun 2005
Article Copyright 2005 by Dalibor Drzik
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid