I am looking for a method to place some text onto the clipboard with VBScript. The VBScript in question will be deployed as part of our login script. I would like to avoid using anything that isn't available on a clean Windows XP system.
Edit: In answer to the questions about what this is for.
We wanted to encourage users inside our organization to use the file server to transfer documents instead of constantly sending attachments by email. One of the biggest barriers to this is that it isn't always obvious to people what the correct network path is to a file/folder. We developed a quick script, and attached it to the Windows context menu so that a user can right click on any file/folder, and get a URL that they can email to someone within our organization.
I want the URL displayed in the dialog box to also be placed onto the clipboard.
Microsoft doesn't give a way for VBScript to directly access the clipboard. If you do a search for
'clipboard'
on this site you'll see:So using notepad indirectly is probably about the best you'll be able to do with just VBScript.
Another solution I have found that isn't perfect in my opinion, but doesn't have the annoying security warnings is to use clip.exe from a w2k3 server.
http://www.petri.co.il/quickly_copy_error_and_display_messages.htm
Example with a multiline string as per question below
I've found a way to copy multi line information to clipboard by vbscript/cmd.
Sequence:
Example script:
I devised another way to use IE and yet avoid security warnings...
By the way.. this function is in JavaScript.. but u can easily convert it to VBScript..
Here's another version of using the "clip" command, which avoids adding a carriage return, line feed to the end of the string:
I've only tested this in XP. clip.exe was downloaded from http://www.petri.co.il/downloads/clip.zip and placed in C:\ .
The easiest way is to use built-in
mshta.exe
functionality:To put to clipboard a string containing double quote char
"
, use the below code: