How to Copy a Textfile to the Clipboard

email me

If WScript.Arguments.Count Then
Const FOR_READING    = 1
Const MAX_CHARACTERS = 8192
Set fs = WScript.CreateObject(“Scripting.FileSystemObject”)
Set f  = fs.OpenTextFile(WScript.Arguments(0), FOR_READING)
t = f.Read(MAX_CHARACTERS)
With WScript.CreateObject(“InternetExplorer.Application”)
.Navigate “about :blank”
Do Until .ReadyState = 4 : WScript.Sleep 50 : Loop
.document.ParentWindow.ClipboardData.SetData “text”, t
End With
f.Close
End If

Perform these steps to implement the script in the txtfile’s right-click context menu:

•Save the code as C:\WINDOWS\system32\Cop2Clip.vbs
•Start regedit.exe and expland the HKCR\txtfile key in the left pane
•Right-click HKCR\txtfile\shell and create a new key called Cop2Clip
•Mark HKCR\txtfile\shell\Cop2Clip and double-click the (Default)-entry in the right pane.
•Enter “C&opy file contents to clipboard” – this text will appear in the context menu.
•Right-click HKCR\txtfile\shell\Cop2Clip and create a new key called command
•Mark HKCR\txtfile\shell\Cop2Clip\command and double-click the (Default)-entry in the right pane.
•Enter C:\WINDOWS\system32\wscript.exe C:\WINDOWS\system32\Cop2Clip.vbs //nologo “%1″ – this is the command line that will be executed if you choose the new Copy file contents to clipboard context menu item.