Monday, January 05, 2009

WSH and clipboard access

I did some Windows Script Host programming recently and I was pleasantly surprised by its power, features and flexibility. One thing that I couldn't accomplish was accessing the clipboard from WSH. Digging the internet I found some solutions like this one based on Internet Explorer Automation. There are several problems with this approach as you can read in my article about Internet Explorer Automation: What's wrong with Internet Explorer Automation?

My solution for scripting the clipboard content in WSH is a regular COM object created with VC++ and ATL.

Download full source code and compiled DLL:
To install the COM object run register.bat

I found scripting the clipboard useful enough to add this feature to the next release of Twebst Web Automation Library.


Ben Larson said...
This comment has been removed by the author.
Anonymous said...

John G
(Russia, Ekaterinburg)

Excellent Object. Thanks

Unknown said...

You are welcome!

BrakTalk said...

Since the code highlighting isn't supported here, I thought I would link to a post I made at your entry:

Any advice or perhaps I'm doing something wrong (I'm new at coding so I wouldn't be surprised.) ;)


Anonymous said...

HI CC. thank you for sharing this. I am super-newbie at C(++/#) so you can quickly tell me... does your clipboard handle only teext, or can it handle any clipboard objects, such as a filesystem object (a file, folder, etc)?

Anonymous said...

To Clarify... my intention is to create a simple script allows me to right-click on a file or folder "shortcut" and copy the target (not the .lnk). Then when the user navigates to the desired directory its a simple native-system right-click paste to copy the shortcut target object to there.
cheers, TwoHawks

Unknown said...

The COM clipboard object I presented here can only handle text. In C++/C# you have specific API to work with clipboard.

TwoHawks said...

Thank you.