Do you have a scripting-related question or problem? You can send your question or problem to [email protected]
After reading Dick Lewis, "How to Take Advantage of the Hidden Streams in Your Scripts," November 2000, I typed the code that Listing 1 shows, then added the line
For /f "token=*" %%i in (C:\teststreams.bat:%1) Do %%i
to C:\teststreams.bat. When I try to run the script on a machine running Windows NT Workstation, I receive the error message C:\"FOR /F "token=*" %i in (C:\teststreams.bat:MyPassword) Do %i token=*" was unexpected at this time. Do you know what the problem might be?
The problem is a typographical error in the For command. The For command's tokens keyword is plural, not singular. If you insert the letter s between token and the equal sign (=), you should be set.
One word of caution I want to pass along about using multiple NTFS data streams is that not all editors support them, including two popular Windows Script (WS) editors: TextPad 4.4.0 from Helios Software Solutions and PrimalSCRIPT 2.0.239 from SAPIEN Technologies. If you use an editor that doesn't support multiple NTFS data streams to edit and save a file containing multiple data streams, you lose the data in the named streams. Thus, make certain your favorite editor supports multiple NTFS data streams if you want to use them.
At my company, we test all applications before we install them in the production environment. I developed a set of procedures to test the effect of installing new or upgraded applications on NT and Microsoft Office 2000 products. I'm now writing scripts to automate this testing process. In one script, I'm using the Document object's PrintOut method, which is part of the Microsoft Word object model. However, I receive the error message Type mismatch: 'PrintOut' when the code in Listing 2 executes. What am I doing wrong?
The PrintOut method's Pages parameter lets you embed nonnumeric characters in its value, such as commas to separate individual page numbers and hyphens to identify a range of pages to print. The Pages parameter is a string subtype. As such, you must enclose the literal value (i.e., the value that is hard-coded in the script rather than stored in a variable as a string) inside double quotes (""). In this case, you need to specify "31-34". Otherwise, VBScript interprets a value such as 31-34 as a numeric expression, which results in the type mismatch error you received.
Another subtle error I noticed concerns the use of VBScript's line-continuation character, which is an underscore (_). You must always insert a space before the line-continuation character. Not inserting the space can result in a syntax error.
I searched high and low for references that discuss how to use VBScript with Office applications and am puzzled by the scarcity of such materials. Can you point me in the right direction?
I encourage you to check out Paul Lomax, Matt Childs, and Ron Petrusha, VBScript in a Nutshell (O'Reilly & Associates, 2000). Although this book doesn't provide comprehensive coverage of scripting Office 2000 applications, it describes the differences between Visual Basic for Applications (VBA) and VBScript and some challenges you'll encounter accessing object models from VBScript. Beyond that, Microsoft's developer edition of Office 2000 is a good source for information specific to the Office 2000 object model.
How can I execute VBScript (.vbs) files remotely?
You have several options to run scripts remotely. You can place the .vbs file on the remote machine and use the NT shell At command to schedule the script to run at a specified date and time. You can also use Windows Management Instrumentation (WMI). The WMI Win32_Process class includes the Create method, which lets you create a process on a remote machine. In both cases, you need to install WS on the target machine. If you use WMI, you also need to install the core WMI components. You can find out where to download WS and WMI in the article "Windows Scripting Resources" in the Web Exclusive section on the Windows Scripting Solutions Web site (http://www.winscriptingsolutions.com).
A new option that you might want to consider is to use Windows Script Host (WSH) 5.6, which is part of WS 5.6 beta 1. WSH 5.6 includes a new feature that lets you run scripts on remote machines. You can download WS 5.6 beta 1 from the Microsoft Windows Script Technologies Web site (http://msdn.microsoft.com/scripting). For information about the new features in WSH 5.6, see Andrew Clinick's November 2000 Scripting Clinic column "Windows Script Host 5.6" (http://msdn.microsoft.com/voices/archive.asp#scripting).
Can I call a Word macro from a remote .vbs file?
Yes, provided that the macro resides in the target document. Suppose you have a document named WordTest.doc that contains a macro called Macro1 residing in the C:\tmp directory on a computer named skunkworks. Using the Application object's Run method, which is part of the Word object model, you can use the code in Listing 3 to call the macro.