Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1149
  • Last Modified:

Write Clipboard Data to a Text file

Here is what I'm looking to do.

1) Copy A field of text to the clipboard(I can do that using SendKeys)
2) Write what I just copied to a Text File (No clue how)
3) Move to a new field and copy that to the clipboard (Again using SendKeys)
3) Copy that field of text to a new line in the same text file (No Clue)

I am hoping I can use a VBScript to output the clipboard to the text file so I can just call that script from a dos batch file, which is what I use to fire off the send keys script. Thanks is advance!!
1 Solution

i just got this article ... read it and give a try...

Hope It will help you..


Hello Clipboard, WSH is calling you
Many scripters wish to interact with the clipboard. Although WSH doesn't provide methods to do that, you can use a few tricks. Let's go step by step.

The most efficient way will be to write an ActiveX control that provides you with methods allowing you to access Windows clipboard. I wrote such a control and shipped it with the MS Press title Inside Windows Script Host, 2. Ausgabe (and there are also plans that my upcoming English MS Press title Advanced Development with Microsoft Windows Script Host 2.0 will contain this control). But till now I'm not ready to release this stuff in the WSH Bazaar (because the description is still in German). That's odd, but fortunately there are a few way to overcome this situation.

Well, maybe you intend to control two applications using WSH, and your script need to force one program to transfer data to the other. In this case you can force the application to copy data to clipboard and paste it into the document area of the other program. This will be used. The script launches Notepad and Calc, forces Calc to evaluate an expression and transfer the result to Notepad.

' File:   AppActivateWSH2.vbs (WSH 2.0 VBScript sample)  
' Author: (c) G. Born www.borncity.de
' Launch Calc and Notepad, use AppActivate to
' switch between applications. Transfers data
' between Calc and Notepad using Clipboard (controlled
' by SendKeys.
' Attention: The script requires WSH 2.0 !!!
Option Explicit

' Define the title strings of the application windows
' Use the title's begin or end, if a file name changes
' Important: strings depend on the localized Windows version
Const Edit_Title = "Notepad"          ' window title
Const Calc_Title = "Calculator"        ' window title


' Create the Shell object, required for Run and AppActivate
Set Wsh = WScript.CreateObject("WScript.Shell")

' we try to launch two applications - to assure that the
' last application receives the focus, we delay the script
Wsh.Run "Calc.exe",1     ' launch Windows calculator
WScript.Sleep 300        ' delay, till calc gets the focus
Wsh.Run "Notepad.exe",1  ' launch Windows editor Notepad
WScript.Sleep 300        ' delay, till notepad gets the focus

' set the focus back to the calculator window & calulate
If Wsh.AppActivate (Calc_Title) Then
 Wsh.SendKeys "10"       ' send 10
 Wsh.SendKeys "{+}"      ' send +
 Wsh.SendKeys "2"        ' send 2
 Wsh.SendKeys "="        ' send =

 Wsh.SendKeys "^{c}"     ' send Ctrl+C, copy to clipboard
End if

' set the focus to the editor window
MsgBox "Paste result into editor window?", vbOkOnly + vbSystemModal
If Wsh.AppActivate (Edit_Title) Then
 Wsh.SendKeys "Result of 10 {+} 2 ="
 Wsh.SendKeys "^{v}"     ' send Ctrl+v, paste from clipboard
End if
'* End

You can use similar techniques also with other application programs. Then you need to send keystrokes to select portions of the document area (which can be a problem).

CannibaltroutAuthor Commented:
Const Edit_Title = "Path Group Maintenance"          ' window title
Set Wsh = WScript.CreateObject("WScript.Shell")
Wsh.AppActivate (Edit_Title)

That works awsome, hopefully when I switch back and forth 52000 times for what I need it to do it will still be working lol.


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now