VBscript: Copy to Clipboard Without Internet Explorer

VBscript Icon
[CODING] Desktop programming is one of the fastest way to develop a program on a manged computer without administrative rights. For example, Microsoft Visual Basic Advanced and Microsoft Visual Basic Scripting Edition.

They are not the best programming technology but they can do awful lot, likely to work on nearly all other computers without additional preparation, work straight out of standard Office and Windows installation. All the ideal conditions in a small office environment.

That's how I come across to write lots of programs this year. And today I am sharing one excellent resource on how to copy to Windows clipboard without Internet Explorer.

If you have arrived at this page while Googling for a routine to perform the copying, congratulations! I think you found what you want or rather, what you don't want; to use Internet Explorer to copy to clipboard. Somehow it is the most popular or if I may, the one and only option on the first few pages on Google.

The solution to copy to clipboard in VBscript without Internet Explorer, is on one of my favourite blog when it comes to Windows PowerShell. The ironic part is that it is not the content of the post that offered the solution. It is in one of the comment section further down the page.

Nevertheless, thank you ScriptingGuy1 and benj9 for the solutions!

Source: Hey, Scripting Guy! Blog Learn about Windows PowerShell
Set oFs = CreateObject("Scripting.FilesystemObject")
Set oWsh = CreateObject("WScript.Shell")
SetClipboard "Hello Clipboard"
WScript.Echo GetClipboard()
WScript.Quit
Sub SetClipboard(sText)
Dim sFile, oFile
sFile = oWsh.ExpandEnvironmentStrings("%TEMP%")
If sFile = "%TEMP%" Then sFile = "."
sFile = sFile & "~SetClipboard.hta"
WScript.Echo sFile
If Not oFs.FileExists(sFile) Then
Set file = oFs.CreateTextFile(sFile, True)
file.WriteLine ""
file.Close : Set file = Nothing
End If
oWsh.Run sFile & " " & sText, 0, True
End Sub
Function GetClipboard()
GetClipboard = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text")
End Function
Next PostNewer Post Previous PostOlder Post Home