Click here to Skip to main content
Click here to Skip to main content

Lock workstation

By , 5 Jun 2005
 

Introduction

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) ();
        }

        FreeLibrary(hinstLib);
    }
    else
        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.

License

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
Member
Wink | ;-)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralLogging inmemberJAQ224 Feb '07 - 5:31 
Is there a way to log back into the user account automatically? I'm trying to create an auto login program that uses input from USB or RS232 to login to windows.
 
Thanks
 
Jack Duece
AnswerRe: Logging inmemberDalibor Drzik24 Feb '07 - 23:57 
I'm not sure... due to security.
Questionwin 2Ksusslevsky17 Oct '05 - 5:16 
Hi
Very sipmle and maybe stupid question
I never setup to lock my windows during configuration of Win2K Pro
and it was OK until several dayes now it start loking me up asking fro user name and passwork in several min as soon as I had left working...
Do you know waht need to be done to correct this
 

Thanx
 
Lev
AnswerRe: win 2KmemberDalibor Drzik17 Oct '05 - 6:54 
Check your setting in Display - [Screen Saver] - [x] On resume, password protect or in Power Options - [Advanced] - [x] Prompt for password when computer resumes from standby.
NewsRe: win 2Ksusslevsky17 Oct '05 - 7:14 
Thanx
I got change for System Standby - never to 30.min
I know that I have not don that it just start happening it self
System MAGICK

GeneralAlso known as..memberAlexander M.6 Jun '05 - 10:22 
> rundll32 user32.dll,LockWorkStation
 
Don't try it, just do it! Wink | ;-)
GeneralRe: Also known as..memberDalibor Drzik7 Jun '05 - 2:37 
Yes, of course. There are many possibilities. E.g. WinKey + L in Windows XP.
 
This article (or code example) is an introduction for my next two articles.

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

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