2

My desktop is extended in two monitors and I want to take screenshot of desktop of 2nd monitor from command line (cmd/powershell).

Any Idea?

mini
  • 71
  • 1
  • 10
  • 1
    Possible duplicate of [Take a screen shot from command line in Windows](https://superuser.com/questions/75614/take-a-screen-shot-from-command-line-in-windows) – Ahmed Ashour Mar 04 '19 at 14:30

1 Answers1

2

This (untested) PowerShell snippet can get you started. Remember that for an extended screen the pixel coordinates are continuous on both screens, from the left-most screen to the right-most:

$File = "\mypath\myscreenshot.bmp"
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
# Gather Screen resolution information
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$Width = ..2nd monitor width in pixels..
$Height = ..2nd monitor height in pixels..
$Left = ..2nd monitor starting left pixel..
$Top = ..2nd monitor starting top pixel, normally zero..
# Create bitmap using the top-left and bottom-right bounds
$bitmap = New-Object System.Drawing.Bitmap $Width, $Height
# Create Graphics object
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
# Capture screen
$graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)
# Save to file
$bitmap.Save($File) 
harrymc
  • 455,459
  • 31
  • 526
  • 924