Subscribe to Windows IT Pro
May 28, 2000 12:00 AM

How can I lock a workstation from the command line?

Windows IT Pro
InstantDoc ID #14925
Rating: (9)

A. Windows 2000 enables you to lock the workstation by typing the following command

C:\> rundll32.exe user32.dll,LockWorkStation

You could also use this as a shortcut on you desktop.

This will not work in Windows NT 4.0. To achieve a similar effect requires a bit more work:

you can use the SendMessage call to send a SC_SCREENSAVE message to the topmost window, which locks the workstation if the current user has a screen saver configured and the screen saver is configured to require a password.

To ensure that a screen saver is configured, you can create registry entries. Run a registry (.reg) file that adds the following entries from the command line: 
HKCU\Control Panel\Desktop\ScreenSaveActive = 1
HKCU\Control Panel\Desktop\ScreenSaverIsSecure = 1
HKCU\Control Panel\Desktop\ScreenSaveTimeout = timeout in seconds
HKCU\Control Panel\Desktop\SCRNSAVE.EXE = %SystemRoot%\System32\Appropriate screen saver.scr
Some screen savers require additional parameters in HKCU\Control Panel\Screen Saver.screen saver name as well.

After you create these registry entries, the following call invokes the screen saver: 
SendMessage(HWND_TOPMOST, WM_SYSCOMMAND, SC_SCREENSAVE, 0) 
You must write and compile a short program (.exe file) that contains this call. You can then call your program from the command line to activate the screen saver. Because the ScreenSaverIsSecure value in the registry has been set to 1, this has the effect of locking the workstation.


Related Content:

ARTICLE TOOLS

Comments
  • Anonymous User
    7 years ago
    Jun 19, 2005

    this is shat in fact its more than shat its bullshat

  • pavnickb
    8 years ago
    Jul 21, 2004

    To perform this command and any other command remotely you can use WMI.

    More specifically you can use the Win32_Process class to create a new process. An example of this would be:

    '/////////////
    '/////////////
    Call subCreateProcess("Computer1", c:\\winnt\\system32\\rundll32.exe user32.dll,LockWorkStation)

    Sub subCreateProcess(strComputer, strCommand)
    Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\\\" & strComputer & "\\root\\cimv2")
    Set objWMIProcess = objWMI.get("Win32_Process")
    objExec = objWMIProcess.Create(strCommand,NULL,NULL,fnCreateProcess)
    End Sub
    '/////////////////
    '/////////////////

  • vaipru
    8 years ago
    Apr 23, 2004

    how can i run applicaton to remote computer by my computer connecting with lan ?

  • Don Weber
    12 years ago
    Oct 10, 2000

    I would like to do this on a remote workstation, using the method for copy/command on remote workstation, ie.. net view >list.txt then doing a batch file for copy operations, I can't seem to get the rundll or user32 command to work on remote computer.

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.