JSI Tip 10147. How can my batch script place text in the Clipboard?


I have scripted PasteClipBoard.bat to paste a text string to the Clipboard.

The syntax for using PasteClipBoard.bat is:

\[Call\] PasteClipBoard Content

Where Content is the string you want to paste.

Examples:

PasteClipBoard Hello

PasteClipBoard "Hello world"

PasteClipBoard.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: PasteClipBoard content&goto :EOF
if exist "%TEMP%\PasteClipBoard.vbs" goto doit
@echo Dim objArgs>"%TEMP%\PasteClipBoard.vbs"
@echo Set objArgs = Wscript.Arguments>>"%TEMP%\PasteClipBoard.vbs"
@echo Content = objArgs(0)>>"%TEMP%\PasteClipBoard.vbs"
@echo Set objIE = CreateObject("InternetExplorer.Application")>>"%TEMP%\PasteClipBoard.vbs"
@echo objIE.Navigate("about:blank")>>"%TEMP%\PasteClipBoard.vbs"
@echo objIE.document.parentwindow.clipboardData.SetData "text", Content>>"%TEMP%\PasteClipBoard.vbs"
@echo objIE.Quit>>"%TEMP%\PasteClipBoard.vbs"
:doit
cscript //nologo "%TEMP%\PasteClipBoard.vbs" %1



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish