Running Scripts with the CScript and WScript Utilities
|
|
|
|
| Articles Reviews Microsoft Windows | |
| Written by Adi Bach | |
| Friday, 15 December 2006 | |
|
Windows supports two methods of starting scripts. The CScript application works at the command prompt, while the WScript application works from within the graphical user environment. Both applications accomplish the same task—they provide a means for interpreting a script file you create. CScript and WScript use the same command line. You must provide a script name as the first command line argument. Most scripts have a VBE or JS file extension, but any extension is acceptable. For example, you can still use VBS files with Windows Scripting Host (WSH), but the icon won’t look right, in some cases, and you can’t double-click it to start the execution with newer Windows products.
The VBS extension is the right choice for older versions of Windows. The icon is yellow for VBE files and blue for JS files. These utilities use the following syntax:
The following list describes each of the command line arguments: //? Displays the currently documented command line switches. The newest versions of WSH tend to reject older switches, even those of the undocumented variety. //D Activates debugging mode so you can fix errors in a script. //Logo and //NoLogo WSH normally prints out a logo message. You’d use the //NoLogo switch to prevent WSH from displaying this message. //S: This command line switch allows you to save current command line options for a user. //T:TimeLimit Limits the maximum time the script can run to the number of seconds specified. Normally, there isn’t any timeout value. You’d use this switch in situations where a script might end up in a continuous loop or is unable to get the requested information for other reasons. For example, you might use this switch when requesting information on a network drive. Notice that all of these command line switches start with two slashes (//) to differentiate them from switches you may need for your script. WSH passes script arguments to your script for processing. Script arguments can be anything including command line switches of your own or values needed to calculate a result. Users of older versions of CScript and WScript may remember the //C and the //W switches used to switch the default scripting engines. Newer versions of CScript and WScript replace these switches with the //H switch. You'll also find the //R (reregister) and //Entrypoint switches missing from WSH because script developers no longer need the functionality. You could use Task Scheduler to accomplish this task, but using it in conjunction with a WSH script improves the flexibility you get when running the task. You’d use it for tasks such as cleaning the hard drive because you don’t always know whether the user needs a particular file. Such a script could ask the user a set of general questions, and then clean excess files from the hard drive based on the user input. The cleaning process would follow company guidelines and save the user time. Because batch processing doesn't require any form of user input, it’s usually a good idea to include the //T switch with the //B switch. This combination stops the script automatically if it runs too long. In most cases, using this switch setup stops an errant script before it corrupts the Windows environment or freezes the machine. However, you can't time some tasks with ease. For example, any Web-based task is difficult to time because you can't account for problems with a slow connection. In this case, you'll need to refrain from using the //T switch or provide a worst-case scenario time interval. The next set of command line switches to consider is //Logo and //NoLogo . There isn’t any right or wrong time to use these switches, but you usually use the //Logo switch when testing a script and the During the testing process, you want to know about every potential source of problems in your script environment, including an old script engine that might cause problems. On the other hand, you don’t want to clutter your screen with useless text after you debug the script. Using the //NoLogo switch keeps screen clutter to a minimum. Powered by jReviews |
|
| Last Updated ( Tuesday, 15 January 2008 ) | |
| < Prev | Next > |
|---|







