Use a Lock Screen

by Dec 12, 2013

With WPF, PowerShell can create windows in just a couple of lines of code. Here's a funny example of a transparent screen overlay.

You can call Lock-Screen and submit a script block and a title. PowerShell will then lock the screen with its overlay, execute the code and remove the lock screen again.

function Lock-Screen([ScriptBlock] $Payload={Start-Sleep -Seconds 5}, $Title='Busy, go away.')
{
    try
    {
      $window = New-Object Windows.Window
      $label = New-Object Windows.Controls.Label

      $label.Content = $Title
      $label.FontSize = 60
      $label.FontFamily = 'Consolas'
      $label.Background = 'Transparent'
      $label.Foreground = 'Red'
      $label.HorizontalAlignment = 'Center'
      $label.VerticalAlignment = 'Center'

      $Window.AllowsTransparency = $True
      $Window.Opacity = .7
      $window.WindowStyle = 'None'
      $window.Content = $label
      $window.Left = $window.Top = 0
      $window.WindowState = 'Maximized'
      $window.Topmost = $true

      $null = $window.Show()
      Invoke-Command -ScriptBlock $Payload
    }
    finally { $window.Close() }
}

$job = 
{ 
  Get-ChildItem c:\windows -Recurse -ErrorAction SilentlyContinue
}

Lock-Screen -Payload $job -Title 'I am busy, go away and grab a coffee...' 

As you will soon discover, the look screen does protect against mouse clicks, but it won't shield the keyboard. It's just a fun technique, no security lock.

Twitter This Tip! ReTweet this Tip!