PowerShell: Locking Workstation

If you ever feel the need to lock your interactive session via PowerShell, here’s a function that can do this (and also illustrates how to use low-level API functionality):

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
}
No comments yet.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

revia in alcoholism