How can I load an image directly into the Windows clipboard from the command line?

2

My dad asked me how he could script the pasting/inclusion of images in various applications. I'm sure I could script out some quick <img src=... HTML but I believe he's also looking to do this in Windows GUI applications like Word or Outlook.

So, how could I script a process with the following inputs and outputs:

  1. load_image_into_clipboard_script.cmd sample_file.jpg
  2. Clipboard now contains the aforementioned image file, just as if I'd e.g. opened it in Paint and done a Select All -> Copy.

I noticed there's a clip.exe utility with Vista/Win2003 and up; perhaps that will be a useful intermediary?

Daniel J. Pritchett

Posted 2011-02-28T14:58:47.833

Reputation: 148

Answers

5

To copy an image into the clipboard, use in the script the tool NirCmd with the copyimage action :

nircmd.exe clipboard copyimage "image-file"

However, to cause any application whatsoever to paste the clipboard image is much harder.

harrymc

Posted 2011-02-28T14:58:47.833

Reputation: 306 093

When I do this with png I get a black background instead of transparent. Any solutions? – Mark – 2015-11-21T21:51:35.080

@Mark: Get in touch with NirSoft.

– harrymc – 2015-11-22T06:15:06.370

I set up a quick two-step copy and notification process and then hid it behind a Windows shortcut I can invoke with ctrl-shift-alt-S: nircmd.exe clipboard copyimage "filename.JPG" msg dpritchett Signature loaded into clipboard! – Daniel J. Pritchett – 2011-02-28T15:51:00.493