title: Powershell - How to get window screenshot while screen is locked?
body: <p>Is there any way to get image of a window while screen is locked?</p>
  
  <p>I'm using Get-Screenshot from RoughDraft to capture window screenshot, but apparently it doesn't work while screen is locked.</p>
  
  <p>In our environment we are using Powershell, so my script looks like this:</p>
  
  <pre><code>Add-Type -TypeDefinition @"
  using System;
  using System.Runtime.InteropServices;
  
  public static class Win32Api
  {
    public static uint WM_CLOSE = 0x10;
  
    [System.Runtime.InteropServices.DllImportAttribute( "User32.dll", EntryPoint =  "GetWindowThreadProcessId" )]
    public static extern int GetWindowThreadProcessId ( [System.Runtime.InteropServices.InAttribute()] System.IntPtr hWnd, out int lpdwProcessId );
  
    [DllImport("user32.dll", CharSet = CharSet.Unicode)]
    public static extern IntPtr FindWindow(IntPtr sClassName, String sAppName);
  
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
  
    [DllImport("kernel32.dll")]
    public static extern uint GetLastError();
  }
  "@
  ....cut....
  
  try {
      while ($ProcessActive.Id -ne $null) {
      $find_window = [Win32Api]::FindWindow([IntPtr]::Zero, $wname )
      $ProcessActive = Get-Process -Id $app.Id -ErrorAction SilentlyContinue
  
      $get_pid = [Win32Api]::GetWindowThreadProcessId( $find_window, [ref] $dbPID );
  
      if ($find_window -ne 0 -And $dbPID -eq $app.Id) {
          Write-Host "[ERROR]  Warning window found:" $find_window -NoNewline
          Write-Host ", and has parent PID:" $dbPID
  
      if (Test-Path warning-$dbPID-scr0.JPEG) {
         Write-Host "[STATUS] Old screenshot file exist, cleaning..."
         Remove-Item warning-$dbPID-scr0.JPEG
      }
          Get-ScreenShot -OfWindow -Path warning-$dbPID-scr
  
          if (Test-Path warning-$dbPID-scr0.JPEG) {
             Write-Host Saved screenshot as warning-$dbPID-scr0.JPEG
          }
      else {
        Write-Host "[ERROR]  Error while saving screenshot!"
      }
  
          $zero = [IntPtr]::Zero
          $send_close = [Win32Api]::SendMessage( $find_window, [Win32Api]::WM_CLOSE, $zero, $zero )
  
          Write-Host "[ERROR]  Exit with code 1 (this is not good)"
          exit 1
      }
  catch {
     $ErrorMessage = $_.Exception.Message
     Write-Host "We'v got this: $ErrorMessage"
  }
  </code></pre>