Click here to Skip to main content
15,879,535 members
Articles / Desktop Programming / Win32
Tip/Trick

How to Lock Windows NT Workstation

Rate me:
Please Sign up or sign in to vote.
4.91/5 (14 votes)
24 Apr 2010CPOL 19K   7   1
Introduction How can you lock your Windows NT based Workstation programmatically? To do this, you just need a little basic knowledge on how to use user32.dll. Here you will find a function name as LockWorkStation() and you need to know how to call this function. A sample example with the...

Introduction

How can you lock your Windows NT based Workstation programmatically? To do this, you just need a little basic knowledge on how to use user32.dll. Here you will find a function name as LockWorkStation() and you need to know how to call this function. A sample example with the description of the function LockWorkStation() is given below:
  • LockWorkStation(): Locks the workstation's display. Locking a workstation protects it from unauthorized use.  

Parameters

This function has no parameters.

Return Value

If the function succeeds, the return value is nonzero. Because the function executes asynchronously, a nonzero return value indicates that the operation has been initiated. It does not indicate whether the workstation has been successfully locked.

If the function fails, the return value is zero. To get extended error information, call GetLastError. More information can be found at http://msdn.microsoft.com/en-us/library/aa376875%28VS.85%29.aspx[^].

Code

VB.NET
   Private Sub LockWinNTWorkStation()
        Try
            LockWorkStation()
        Catch ex As Exception
            MsgBox("This is not relevant for " _
                            & Environment.OSVersion.ToString() _
                            & ". Windows NT based Operating System is required.", MsgBoxStyle.Exclamation)
        End Try

    End Sub

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
GeneralMy vote of 3 Pin
programmerdon21-Aug-12 3:47
programmerdon21-Aug-12 3:47 

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.