Script Properties and .wsh Files
In the previous two sections, you saw that the WScript and CScript hosts have a number of parameters you can specify when you execute a script. It's also possible to set some of these options by using the properties associated with each script file. To see these properties, right-click a script file and then click Properties. In the properties sheet that appears, display the Script tab, shown in Figure 37.1. You have two options:
- Stop Script After Specified Number of Seconds—If you activate this check box, Windows shuts down the script after it has run for the number of seconds specified in the associated spin box. This is useful for scripts that might hang during execution. For example, a script that attempts to enumerate all the mapped network drives at startup might hang if the network is unavailable.
- Display Logo When Script Executed in Command Console—As you saw in the previous section, the CScript host displays some banner text when you run a script at the command prompt. If you deactivate this check box, the Windows Script Host suppresses this banner (unless you use the //LOGO parameter).
Figure 37.1 In a script file's properties sheet, use the Script tab to set some default options for the script.
When you make changes to these properties, the Windows Script Host saves your settings in a new file that has the same name as the script file, except with the .wsh (Windows Script Host Settings) extension. For example, if the script file is MyScript.vbs, the settings are stored in MyScript.wsh. These .wsh files are text files organized into sections, much like .ini files. Here's an example:
[ScriptFile] Path=C:\Users\Paul\Documents\ScriptsCreateShortcut.vbs [Options] Timeout=10 DisplayLogo=0
To use these settings when running the script, use either WScript or CScript and specify the name of the .wsh file:
wscript myscript.wsh