If you explicitly specify a host (e.g., when you preface the script's name with either the Cscript or Wscript command), you must also type the script's file extension. For example, the command

cscript hello 

won't work, but

cscript hello.vbs 

will (assuming, of course, that a script file named hello.vbs exists in the current directory). Typing a script name without a host or an extension at the command prompt causes the default host to execute the script.

To see which is the current default scripting host, right-click a script file in Windows Explorer. If the bold menu item is Open with Command Prompt, then the default host is CScript. If the bold menu item is Open, the default host is WScript.

Script File Properties
You can open a Properties dialog box for a script file by right-clicking the script file in Windows Explorer and choosing Properties. Go to the Script tab, which Figure 1 shows. The two options on this tab correspond to the //T and //Logo (or //Nologo) command-line options. If you change either of the options and click OK, Windows creates scriptname.wsh in the same directory as the script. The .wsh file is a plaintext file that contains the selected options; Figure 2 shows a sample .wsh file. The sample .wsh file's BatchMode setting isn't accessible via the GUI and corresponds to the //B command-line option. When it's set to zero (the default), the script will run in interactive mode (//I); if set to 1, the script will run in batch mode (//B). If you want to use this setting, you'll need to open the .wsh file in Notepad or another editor and add the setting.

A .wsh file is merely a way of executing a script with predefined options. When you open a .wsh file, its associated script is executed with the WScript host. Oddly, the //H command-line option doesn't change the default script host for .wsh files. To use CScript to run a .wsh file from the GUI, right-click the file and choose Open with Command Prompt. In a command window, type

cscript <.wsh filename> 

A .wsh file contains the full path to its associated script file, so it's possible to move the .wsh file to a different location and still execute the related script. Also, .wsh files aren't strictly necessary; you can always execute a script with the desired settings by using the CScript or WScript command-line options.

WSH File Extensions
Table 2 shows a list of the standard file extensions that WSH uses. Standalone script files use the .js and .vbs extensions. Other ActiveX scripting engine languages use their own extensions (e.g., .pl for Perl, .py for Python). Standalone scripts are the most common because they're the easiest to write.

XML-formatted WSH scripts, .wsf files, are more flexible than standalone scripts because they can contain code written in more than one script language. They also provide some other useful features, such as the ability to include script code from other files. XML-formatted text files that contain the code for script-based objects have the .wsc extension. I'll discuss .wsf scripts and .wsc script components in more detail in future articles in this series.

Clearing Up WSH Confusion
I hope that this explanation helps clear up some of the confusion about WSH and its related collection of file extensions. Next time, I'll describe .wsf scripts and the additional features they provide beyond standalone scripts.

End of Article

Prev. page     1 [2]     next page -->



You must log on before posting a comment.

If you don't have a username & password, please register now.

 
 

ADS BY GOOGLE