

Set objFSO = CreateObject(“Scripting.FileSystemObject”) Next, create a second script – give it any name you want – and paste this code into it: Const OverwriteExisting = TRUE Can we do such a thing? You bet we can.įirst, save the preceding script – the one that actually locks the computer – as Lock_workstation.vbs and – for simplicity’s sake – save it to C:\Scripts.

But that’s OK: if this script only runs locally, then all we have to do is make sure it runs locally on the remote computer. This works great for the local computer, but doesn’t do you much good if you’re trying to lock a remote computer you can’t specify a remote computer name when running Rundll32.exe. ObjShell.Run “%windir%\System32\rundll32.exe user32.dll,LockWorkStation” Set objShell = CreateObject(“Wscript.Shell”)
#HOW TO WRITE A SHUTDOWN SCRIPT IN NOTEPAD ON MAC HOW TO#
In fact, the only way we could figure out how to lock a computer using a script was to write a script that did nothing more than use Rundll32.exe to call the LockWorkStation method of user32.dll: On Error Resume Next What the Win32Shutdown method won’t let you do is lock a computer as near as we can tell nothing within WMI allows you to lock a computer. ObjOperatingSystem.Win32Shutdown(SHUTDOWN) Set colOperating Systems = objWMIService.ExecQuery _įor Each objOperatingSystem in colOperatingSystems For example, this script shuts down a computer: Const SHUTDOWN = 1 Most likely you’re familiar with the Win32Shutdown method found in the WMI class Win32_OperatingSystem that method allows you to shutdown or reboot a computer, or log off the current user. But is there any way I can lock a workstation using a script? Hey, Scripting Guy! I know how I can shut down a computer using a script, and I even know how I can log a user off using a script.
