Take a screen shot from command line in Windows

51

19

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

Željko Filipin

Posted 2009-11-26T15:34:16.123

Reputation: 4 067

2@Idigias: first of all, the screen is larger than a CMD box, but secondly : when a script launches a GUI tool, that GUI tool takes focus. So, your "obvious deficiency" is not obvious, and no deficiency either. Have you ever worked with command line ? – tvCa – 2015-04-13T09:49:26.297

Take a look at: https://p.teknik.io/GXO9X

– mini – 2019-03-25T01:11:07.817

1Why would you want to do something like that ? Apart from the obvious deficiency (it being able to take screenshots only of the command line you're currently working on), what's wrong with the "regular" solutions for such purpose ? – Rook – 2009-11-26T15:53:39.033

7Why would it be restricted to take a picture of the cmd line only? I think the question goes more along the lines of automation. – Gerd Klima – 2009-11-26T15:57:04.283

Well, in the moment he wants to take a screenshot, he has to press enter to give the command, doesn't he ? He could of course use a script to time-activate it, but then he's really reinventing hot water. – Rook – 2009-11-26T16:00:13.887

I would like to write a script that opens eml file in Thunderbird, takes a screen shot, opens another file, takes another screen shoot... For all files in a folder. I want to execute screen shot tool from the command line, so it could be automated. Just to be clear, I do not want to take a screen shot of command line, but of the entire screen. In fact, I have already written the script, I am just looking for more options to take the screen shot. – Željko Filipin – 2009-11-27T11:10:21.187

Answers

26

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.jpeg

If 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

DaveParillo

Posted 2009-11-26T15:34:16.123

Reputation: 13 402

It still doesn't work for me. I get a screenshot, but only the X applications show up (as expected). – reinierpost – 2015-10-09T13:11:42.167

hm, ImageMagick is 25 Mb, and does TON of cool stuff. screenCapture.bat, below, is 9 Kb, and simply does exactly what the OP requested. At .04% the size of ImageMagick. – johny why – 2016-04-12T00:59:08.187

13This doesn't seem to work on Windows. I get an X server error about file not found. – Binary Phile – 2011-04-05T18:14:23.267

2@BinaryPhile Yea I think this would only work with an X server running on Cygwin. – CMCDragonkai – 2014-05-12T08:42:34.687

41

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.png

does what you want. You can also delay it like this:

nircmd.exe cmdwait 2000 savescreenshot screen1.png

That will wait 2000 milliseconds (2 seconds), and then capture and save the screenshot.

zacharyliu

Posted 2009-11-26T15:34:16.123

Reputation: 1 675

Nircmd does not support multiple screens. It will capture the primary screen only. – Thomas Weller – 2015-05-19T08:58:09.130

1Looks like the recent versions can do multiple screens.

savescreenshotfull [filename] – w32sh – 2016-02-26T10:47:56.270

I couldn't find the download link for nircmd2 initially. Google search didn't show anything. For users looking to download nircmd2, the download link is located at the very bottom of the page http://www.nirsoft.net/utils/nircmd.html. You can directly use this download link: http://www.nirsoft.net/utils/nircmd.zip

– alpha_989 – 2018-02-01T19:46:14.210

18

it 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 such

Examples:

call screenCapture notepad.jpg "Notepad"
call screenCapture screen.png

npocmaka

Posted 2009-11-26T15:34:16.123

Reputation: 887

2Definitely the best solution. Super-tiny 9K! That's 0.04% the size of ImageMagick (25 Mb). It uses built-in Windows functionality. Tinier than all other solutions on this page. Best! – johny why – 2016-04-12T01:01:14.637

1One thing that I noticed about this solution is that there are specific things that it does not capture. For example, some applications are attaching themselves and creating huds on other applications that are not rendered in the captured image. In those extreme cases I found that MiniCap works. In most cases though, this solution right here is the fastest and most uncomplicated that you can find. – F1234k – 2016-09-05T22:40:59.380

Hi @npocmaka, I have two monitor that desktop is extended on them. I want to take screenshot of desktop of the second monitor. But your program just take screenshots from primary desktop. Any trick? – mini – 2019-03-04T14:02:05.507

@mini - you can edit the c# part of the script using this . I'll try to add add this at the weekend

– npocmaka – 2019-03-04T19:41:52.350

@npocmaka, As I'm not familiar with C#, I'll be waiting for your update. Thanks a lot. – mini – 2019-03-16T05:38:43.540

When I run this command using a Powershell client in Python, it always gives me an exception "Probably there's no window like" for almost everything. – Sankalp – 2019-06-27T09:46:08.693

13

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: http://www.donationcoder.com/Software/Mouser/MiniCap/index.html

(disclaimer: I'm the author of MiniCap).

mouser

Posted 2009-11-26T15:34:16.123

Reputation:

1It is free for personal use only. For commercial use, a license for Screenshot Captor is needed. – Thomas Weller – 2015-05-19T08:59:11.527

1Then you must also be the author of Screenshot Captor. I found it a better solution for my needs. Thank you! – jon3laze – 2012-08-24T20:50:12.887

10

Try 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

john liu

Posted 2009-11-26T15:34:16.123

Reputation: 109

I've using IrfanView for years, never know it could do this. Thanks for sharing. – David Dai – 2019-11-27T08:37:51.393

6

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: http://blog.mozilla.com/ted/2009/02/05/command-line-screenshot-tool-for-windows/

Bartek

Posted 2009-11-26T15:34:16.123

Reputation: 69

1This is open source, BSD license. Very simple and small - for me these are advantages. – Jarekczek – 2015-01-24T12:06:04.983

6

You 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

James

Posted 2009-11-26T15:34:16.123

Reputation: 535

This one supports multiple monitors but adds some extra black area in version 1.5 – Thomas Weller – 2015-05-19T09:19:59.187

For those interested in compactness, boxcutter is only 22K for the full-screen .exe and 502K for the regular .exe. It is open-source. Works great for me. – frakman1 – 2019-01-31T14:57:11.647

2

You can use the Pillow python library to take screenshots of the primary monitor

Step1: install Pillow:

pip install -user pillow

Step2: Take screenshots with the following code:

from PIL import ImageGrab
img = ImageGrab.grab()
img.save('screenshot.bmp')

alpha_989

Posted 2009-11-26T15:34:16.123

Reputation: 623

1First I tried the imagemagic solution, but when I've seen that piece of Python code, I tried it in an interactive Python CLI and a second later I was happy! Thx!! – domih – 2018-07-30T12:02:11.013

1

You can use commercial product snapit to take awesome screenshots from the command line.

Željko Filipin

Posted 2009-11-26T15:34:16.123

Reputation: 4 067

2

This is now a commercial product, needs .NET and is not released for Windows 7++. The link given in the answer returns HTTP 404.

– Thomas Weller – 2015-05-19T09:21:24.453

Yea the GitHub repo doesn't exist. – alpha_989 – 2018-02-01T19:25:11.383