VBScript

Using WSCRIPT in Windows Script Components (WSC)

When searching for an answer as to how to use wscript.echo for logging to the command window from a wsc file, the only thing found was that it is not possible, but we figured out how to make it work anyway.

For my most recent VBScript project, I created automation for populating custom reports in Adobe InDesign CS3 and CS4. I wanted to split up the functionality into separate files, but standard vbs files can only pass values and not actual objects (where the command SET is required to instantiate the object). This would not work for passing around my InDesign object!

I eventually ran into Windows Script Components as a solution for passing actual objects. One of the components I created was for sending logging information to the screen (it runs as cscript) and also to log files. At first I could not figure out how to make wscript.echo and wscript.sleep work. I found several references on the Web that said it couldn't be done. I could not find any evidence that it was possible.

I was so frustrated by this that I played around with it for a couple of hours, then I found it! It is possible to use the wscript object in a wsc file! All you do is pass the wscript object from the main vbs file to the wsc file as a function parameter, then take that parameter (let's name it 'myWscript') and [SET wscriptObj = myWscript] it in the wsc file. Then you can so something like [wscriptObj.echo "Hello World!"]. It works like a charm!

The best part is that I instantiated the logging component in all of my other components and set that script's name as a logging component property. Then whenever I called the logging component from another component (or the main vbs file), the script that called the logging component would display its name in the logs automatically. The result is logging that is very easy to follow for troubleshooting, and very clean code.

 
Add To Favorites