Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

PowerShell – Lock Workstation

Posted on November 9, 2015November 9, 2015 By David Kittell

This is a great script to add to a setup script to lock the workstation after everything is done or before everything starts

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
}

Lock-WorkStation

Reference: http://poshcode.org/6037

All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code PowerShell

Post navigation

Previous post
Next post

Related Posts

Powershell Download Script

Posted on September 11, 2015

# If you haven’t already done so you will need to run this to be able to execute PowerShell scripts # You will need to run PowerShell as administrator to run this script set-executionpolicy remotesigned Pass variables to the script <# .SYNOPSIS Downloads one file from a defined URL to…

Read More

Last Read / Last Write

Posted on April 29, 2013October 26, 2015

Sometimes you need to know the last time a table or database was read from or written to, this code will help determine that for you. Originally Found At: http://blog.sqlauthority.com/2009/05/09/sql-server-find-last-date-time-updated-for-any-table/ USE <Database_name> SET ANSI_WARNINGS OFF; SET NOCOUNT ON; GO WITH agg AS ( SELECT last_user_seek, last_user_scan, last_user_lookup, last_user_update FROM sys.dm_db_index_usage_stats…

Read More

Check For Valid Date

Posted on February 28, 2013October 26, 2015

Recently I had to validate dates in a form specifically the date of visit and date of birth This function will now check both for future date and do more checks for the date of visit, debug/helper information left in to better understand the function. Function Code: public bool bCheckDate(string…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
©2025 David Kittell | WordPress Theme by SuperbThemes