2

Assume I have text in the file textFile.txt. Also assume I have a program running called aProgram.exe, which accepts pasted text.

What is the simplest way to create a script or batch that will capture the text in textFile.txt, open aProgram.exe and paste the contents of my clipboard?

Organised differently, how may I

  1. Place text in textFile.txt into clipoard
  2. Open aProgram.exe (which is already running)
  3. Paste my clipboard on aProgram.exe (Control + V, is what I mean here)

Thank you very much for your help.

2
1

You can use this hybrid bat with vbs to do this with you, just save as file.cmd:

<!-- ::
@echo off & type "C:\folder\path\your\textFile.txt"| clip 
"%windir%\system32\WScript.exe" "%~dpnx0?.wsf" && goto :EOF || rem :: -->
<job><script language="vbscript">Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run ("""C:\\Program Files\\aProgram.exe"""),9
WScript.Sleep 3000: WshShell.SendKeys "^+v": </script></job>

The code above opens your program, edit this path below and according to the location of the program using \\ instead \:

C:\\Program Files\\aProgram.exe

You also need to edit the path to your textFile.txt:

@echo off & type "C:\folder\path\your\textFile.txt" | clip 

You may need to adjust the timeout on:

WScript.Sleep 3000

For do the same in PowerShell

Get-Content -path "C:\folder\path\your\textFile.txt" | Set-Clipboard
Start-Process -FilePath 'C:\\Program Files\\aProgram.exe'
Start-Sleep -m 700
$wshell = New-Object -ComObject wscript.shell
$wshell.AppActivate('add here the aProgram.exe windows name')
Start-Sleep -m 700 
[System.Windows.Forms.SendKeys]::SendWait("^{v}") 

You also need to edit the path to your textFile.txt:

Get-Content -path "C:\folder\path\your\textFile.txt"  | Set-Clipboard 

You may need to adjust the timeout on:

Start-Sleep -m 700
2
  • Thank you very much, Sir. What a fantastic and thoughtful response! Apr 26 '20 at 23:33
  • @GustavoLouisG.Montańo Is good to know that code works for you too, thkx! Sorry my limited /EN! Apr 26 '20 at 23:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.