I am looking for a way to take a screenshot of the entire screen from the command line. Operating system is Windows. Something like this:
C:\>screenshot.exe screen1.png 6 12 Answers
Download imagemagick. Many command line image manipulation tools are included. import allows you to capture some or all of a screen and save the image to a file. For example, to save the entire screen as a jpeg:
import -window root screen.jpegIf you want to use the mouse to click inside a window or select a screen region & save a a png, just use:
import box.png 6 This question's already been answered, but I thought I'd throw this in as well. NirCmd (freeware, sadly, not open source) can take screenshots from the command line, in conjunction with the numerous other functions it can do.
Running this from the command line either in nircmd.exe's directory or if you copied it to your system32 folder:
nircmd.exe savescreenshot screen1.pngdoes what you want. You can also delay it like this:
nircmd.exe cmdwait 2000 savescreenshot screen1.pngThat will wait 2000 milliseconds (2 seconds), and then capture and save the screenshot.
3it can be done without external tools (you just need installed .net framework ,which is installed by default on everything from vista and above) - screenCapture.bat. It is a selfcompiled C# program and you can save the output in few formats and capture only the active window or the whole screen:
screenCapture- captures the screen or the active window and saves it to a file
Usage:
screenCapture filename.format [WindowTitle]
filename - the file where the screen capture will be saved
format - Bmp,Emf,Exif,Gif,Icon,Jpeg,Png,Tiff and are supported - default is bmp
WindowTitle - instead of capturing the whole screen will capture the only a window with the given title if there's suchExamples:
call screenCapture notepad.jpg "Notepad"
call screenCapture screen.png 10 Other suggestions are fine -- you could also try MiniCap, which is free and has some other features like flexible file naming and some different capture modes:
(disclaimer: I'm the author of MiniCap).
2Try IrfanView.
You can run it via command-line. You can specify which window to capture – such as whole window or just the current/active window – and you can also do some basic editing such as sharpening, cropping or resizing the images.
Here are the command line options, particularly interesting is
i_view32 /capture=0 /convert=wholescreen.png 1 Screenshot-cmd takes a screenshot of a desktop or any window selected by window title. It is also possible to select rectangle to capture. The result is stored as a png file. (last update in 2011)
OPTIONS: -wt WINDOW_TITLE Select window with this title. Title must not contain space (" "). -wh WINDOW_HANDLE Select window by it's handle (representad as hex string - f.e. "0012079E") -rc LEFT TOP RIGHT BOTTOM Crop source. If no WINDOW_TITLE is provided (0,0) is left top corner of desktop, else if WINDOW_TITLE maches a desktop window (0,0) is it's top left corner. -o FILENAME Output file name, if none, the image will be saved as "screenshot.png" in the current working directory. -h Shows this help info.Inspired by:
1You can try the boxcutter tool:
usage: boxcutter [OPTIONS] [OUTPUT_FILENAME]
Saves a bitmap screenshot to 'OUTPUT_FILENAME' if given. Otherwise,
screenshot is stored on clipboard by default.
OPTIONS -c, --coords X1,Y1,X2,Y2 capture the rectange (X1,Y1)-(X2,Y2) -f, --fullscreen fullscreen screenshot -v, --version display version information -h, --help display help message 2 You can use the Pillow python library to take screenshots of the primary monitor
Step1: install Pillow:
pip install -user pillowStep2: Take screenshots with the following code:
from PIL import ImageGrab
img = ImageGrab.grab()
img.save('screenshot.bmp') 1 You can use the PowerShell code found here:
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function screenshot([Drawing.Rectangle]$bounds, $path) { $bmp = New-Object Drawing.Bitmap $bounds.width, >$bounds.height $graphics = [Drawing.Graphics]::FromImage($bmp) $graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size) $bmp.Save($path) $graphics.Dispose() $bmp.Dispose()
}
$bounds = [Drawing.Rectangle]::FromLTRB(0, 0, 1000, 900)
screenshot $bounds "C:\screenshot.png" You can use commercial product snapit to take awesome screenshots from the command line.
2On Windows, I managed using the tip from @zacharyliu. For laymen and for those who like portable things I easily did it using Cmder.
Download Cmder. I use the portable version with full installation
Extract Cmder
Open the folder and enter the bin folder (in the same folder as the executable, if not, create one)
Download the NirCmd files (link at the bottom of the page)
Place the NirCmd files in the bin folder
Open Cmder (if it is open restart it)
Use the following code (Saves screenshots.png every 3 seconds 5 times in the
C:\screenshots\MONTH-DAY-YEAR\folder withHOURS-MINUTES-SECONDS.pngname):cd C:\ && ([ -d screenshots ] || mkdir screenshots) && "nircmdc.exe" loop 5 3000 execmd "cd C:\screenshots\ && ([ -d ~$currdate.MM-dd-yyyy$ ] || mkdir ~$currdate.MM-dd-yyyy$) && nircmdc.exe savescreenshot C:\screenshots\~$currdate.MM-dd-yyyy$\screenshot-~$currtime.HH-mm-ss$.png"Enjoy!
How it works, which date formats are supported, which image formats are supported, and other details:
- NirCmd Command Reference - savescreenshot
- NirCmd Command Reference - execmd
- StackOverflow - Only mkdir if it does not exist
I really dislike answers that rely on third-party software, i spent a bit of time coming up with the solution for my problem, so i'll post it here just in case anyone else needs it.
I combined this answer, with a bit of my own implementation to grab only the powershell window:
add-type -namespace native -name winapi @"
[DllImport("user32.dll")]
public static extern int GetWindowRect(IntPtr hwnd, out System.Management.Automation.Host.Rectangle rect);
[DllImport("user32.dll")]
public static extern bool SetProcessDPIAware();
"@
# necessary, otherwise the dimensions are wrong with different DPIs
[native.winapi]::SetProcessDPIAware()
$rect = [System.Management.Automation.Host.Rectangle]::new(0,0,0,0)
$pshwnd = ([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle
[native.winapi]::GetWindowRect($pshwnd, [ref] $rect)
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function screenshot([Drawing.Rectangle]$bounds, $path) { $bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height $graphics = [Drawing.Graphics]::FromImage($bmp) $graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size) $bmp.Save($path) $graphics.Dispose() $bmp.Dispose()
}
$bounds = [Drawing.Rectangle]::FromLTRB($rect.Left, $rect.Top, $rect.Right, $rect.Bottom)
screenshot $bounds "screenshot.png"