Techibee.com

Lock your workstation using PowerShell

One other nice thing I found with PowerShell is it’s ability of using APIs by importing DLLs. Below is one example, where user32.dll is imported and LockWorkstation Function is invoked to lock the desktop. Btw, I grabbed this script from TechNet Library

Function Lock-WorkStation {
$signature = @”
[DllImport(“user32.dll”, SetLastError = true)]
public static extern bool LockWorkStation();
“@

$LockWorkStation = Add-Type -memberDefinition $signature -name “Win32LockWorkStation” -namespace Win32Functions -passthru
$LockWorkStation::LockWorkStation() | Out-Null
}

After executing above code, invoking “Lock-WorkStation” command from PowerShell window will lock your PC.

Happy Learning..,
Sitaram Pamarthi

Exit mobile version