3

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?

1

1 Answer 1

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) 
2
  • To pass arguments to the script see PowerShell Parameters.
    – harrymc
    Commented Mar 20, 2019 at 20:35
  • If it works then all is OK. If not, just post another question.
    – harrymc
    Commented Mar 23, 2019 at 19:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .