Thursday, August 21, 2008

VBScript: How to Lock a Workstation

I'm not a huge fan of VBScript but occasionally I find it a useful tool to employ. I like the fact that it gives me the ability to make a quick, double-click-and-take-action solution, all while using the simplest of code compliers out there; Notepad!

As a quick example, this code can be used to lock a workstation. To create the script just open a new text document in Notepad (not word, if you please) and enter the following:

"""""""Start Code""""""""""""""

On Error Resume Next
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "%windir%\System32\rundll32.exe user32.dll,LockWorkStation"

"""""""End Code"""""""""""""""


Save the file and then change the file extension from .txt to .vbs and there you have it.

(Note, some system admins lock out the .vbs file extension for safety and security reasons so this may or may not work where you work, as it were.)

I typically place a shortcut to this little script in my quick launch bar and use it as a "one click and walk away" convenience at work. Once you launch the script there's pretty much nothing short of a full OS failure that's going to stop the workstation from locking. Comes in handy when you're constantly dashing away from your desk to put out fires.

No comments: