Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

VBS and the Clipboard.


  • Please log in to reply

#1
IO-error

IO-error

    Member

  • Member
  • PipPipPip
  • 276 posts
Hi there. I ran into a problem with my personal project.

I'm using only Notepad++ and not willing to step to something else. (just so nobody advices me to use something else)

I read all about it on the internet that it's possible to copy something to the clipboard, but every single script that I saw has nothing to do with the clipboard in reality.
The example scripts all use IExplore and about:blank and all kinds of stuff that has nothing to do with it.

Some guy explained to me that it needs a parent window to copy something to the clipboard, but in the example script it will not REALLY copy it, it will just write it to the file immediatly, without copying.

My example:

strComputer = "."
	Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set colItems = objWMI.ExecQuery _
		("Select * from Win32_Proxy",,48)

For Each objItem in colItems
	ProxyServer = objItem.ProxyServer
	ProxyPortNumber = objItem.ProxyPortNumber
Next

Proxy = InputBox("Do you want to save the IP to disk?.","Here's your IP and Port.",""&ProxyServer &":" &ProxyPortNumber,800,600)

If Proxy = 1 Then
With Clipboard
	.Clear
	.SetText(""& ProxyServer)
End With
	msgbox("Copied")
		Else msgbox("Copy Failed")
End If

First block gets data from the WMI engine, the proxy server/IP.
Second block assigns names to specific data in the WMI engine.
Third block creates my inputbox with the wanted text. (The Proxy IP/Port)
The last block will copy the text to the clipboard when the user clicks OK and if the user clicks cancel or exits script.

The error message I get says that the types don't match.
  • 0

Advertisements


#2
IO-error

IO-error

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 276 posts
Hi all.

I gave up on this a long time ago, because nobody knew how to do it.
Now I'm back with more research, but no answers...

Set objHTML = CreateObject("htmlfile")
ClipboardText = objHTML.ParentWindow.ClipboardData.GetData("text")
MsgBox ClipboardText

This IS working, but I have no idea how to throw in new data.
I tried google, but I get about 190.000 hits... And I tried 150 random links without any luck.
All the scripts I find are for VBA or VB, not VBS. And the one that was for VBS couldn't set data to the clipboard.
Is the clipboard such a newbie area in VBS?

Thnx in advance
  • 0

#3
IO-error

IO-error

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 276 posts
For those that were trapped like me:

I managed to get it working and made an easy-to-study layout for those that want VBS to put data on the clipboard.
If you have any questions about VBS, you can PM me for my msn-adres.


Dim ClipBoard
'msgbox("0")
Set Clipboard = New cClipBoard

ClipBoard.Clear
ClipBoard.Data = "This text is clipboard data."
'MsgBox ClipBoard.Data

Class cClipBoard
	Private objHTML
	
		Private Sub Class_Initialize
			Set objHTML = CreateObject("InternetExplorer.Application")
			objHTML.Navigate ("about:blank")
'			msgbox("1")
		End Sub
		'TODO When to use Get and Let.
		Public Sub Clear()
			objHTML.Document.ParentWindow.ClipboardData.ClearData()
'			msgbox("2")
		End Sub
			
		Public Property Let Data ( Value )
			objHTML.Document.ParentWindow.ClipboardData.SetData "Text" , Value
'			msgbox("3")
		End Property
	
		Public Property Get Data()
			Data = objHTML.Document.ParentWindow.ClipboardData.GetData("Text")
'			msgbox("4")
		End Property

		Private Sub Class_Terminate
			objHTML.Quit
			Set objHTML = Nothing
'			msgbox("5")
		End Sub
		
End Class

  • 0

#4
jxaxmxixn

jxaxmxixn

    New Member

  • Member
  • Pip
  • 1 posts
Here is my simple way to copy data to the clipboard in VBS.

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd /C echo " & STRING & "  | CLIP", 2

you simply create a shell object, then open a command window telling it to unload (/C) after sending your STRING to the clipboard ( | CLIP)
you'll have to do some extra work for multi line strings...

you can also send the contents of an entire file to the clipboard using CLIP < FILENAME

objShell.Run "cmd /C CLIP < mytext.txt", 2

Get creative with it... ENJOY!
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP