Asking for a way of taking screenshot of 2nd desktop when the desktop is extended in two monitors through windows command line

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

Posted 2019-03-04T14:23:19.717

Reputation: 51

1

Possible duplicate of Take a screen shot from command line in Windows

– Ahmed Ashour – 2019-03-04T14:30:48.593

Answers

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

Posted 2019-03-04T14:23:19.717

Reputation: 306 093

To pass arguments to the script see PowerShell Parameters.

– harrymc – 2019-03-20T20:35:58.563

If it works then all is OK. If not, just post another question. – harrymc – 2019-03-23T19:00:01.450