Include File Support The include file capability lets you place commonly used code in a separate file or files, then reference the file (or files) in other scripts. The separate file's code becomes available to the script that contains the include directive. The <script> element's optional src attribute (src="filename") is the include enabler. Multiple Languages Support WSH 2.0 provides support for multiple languages so that you can use several languages inside one WS file. The <script> element's mandatory language attribute makes switching between languages possible. For example, inside a WS file, you can write part of one job in JScript and write the other part of the job in VBScript. Also, you can pass variables that include object references across code boundaries. The <object> element WSH 2.0 lets you use the <object> element to create objects. The <object> element performs the same task that the WScript, VBScript, and JScript CreateObject, GetObject, and new ActiveXObject methods do. Jobs Jobs let you partition a WS file into autonomous self-contained work units. You use the <job> element's id attribute to give a unique name to each job in the file, and you use the new //job:jobid option to identify the job to execute at runtime. For example, you might use the jobs feature to divide your WS file into discrete tasks in which each job represents a primary script capability. <job id="IncludeExample"> <script language="JScript" src="FSO.JS"/> <script language="VBScript"> ' Get the free space for drive C. s = GetFreeSpace("c:") WScript.Echo s <script> </job> The fso.js file contains the following: function GetFreeSpace(drvPath) { var fs, d, s; fs = new ActiveXObject("Scripting.FileSystemObject"); d = fs.GetDrive(fs.GetDriveName(drvPath)); s = "Drive " + drvPath + " - " ; s += d.VolumeName; s += " Free Space: " + d.FreeSpace/1024 + " Kbytes"; return s; } <job id="PERLandVBS"> <script language="PerlScript"> sub PerlHello { my $str = @_[0]; $WScript->Echo($str); } </script> <script language="VBScript"> WScript.Echo "Hello from VBScript" PerlHello "Hello from PERLScript" </script> </job> CScript //Job:MyFirstJob MyScripts.wsf To display a script's argument list Set objArgs = WScript.Arguments For I = 0 to objArgs.Count - 1 WScript.Echo objArgs(I) Next Setting and Customizing Script Properties (.wsh) You can record specific settings for each of your individual scripts by means of a Windows Script Host control (.wsh) file. The .wsh file is a text document in which you can customize execution of one or more of your scripts. It is created automatically when you set the properties for a supported script file. If you create multiple .wsh files for a single script, you can tailor the way the script runs to the needs of specific groups or even individuals within an organization. For example, you could create a single logon script that is invoked by two different .wsh files that contain different settings and parameters. When you double-click a .wsh file or run it from the command line, CScript.exe or WScript.exe reads the .wsh file to determine the specific settings that should be used to execute the script. CScript/WScript executes the original script, passing in the properties that are defined within the .wsh file. To create a .wsh file for a given script Right-click the script file in Windows Explorer. Click Properties on the shortcut menu. Choose the settings you want for the script. Click OK or Apply. A .wsh file is created with the same name as the script file you selected. The following example illustrates a typical .wsh file: [ScriptFile] Path=C:\WINNT\Samples\WSH\showprop.vbs [Options] Timeout=0 DisplayLogo=1 BatchMode=0 The path information in the [ScriptFile] section identifies the script file that is associated with the .wsh file. The keys in the [Options] section correspond to settings in the Script tab within the Properties dialog box. Note You must have the original script file present when executing the .wsh file. If the .wsh file fails to run the script, check the Path= information in the .wsh file to ensure that it points to the script you are attempting to run. On initial installation, the default host is WScript. To change it to CScript, type the following at the command line: cscript //h:cscript Or, to change it from Cscript to Wscript: wscript //h:cscript WScript.exe and CScript.exe Options
ParameterDescription
//BBatch mode; suppresses command-line display of user prompts and script errors. Default is Interactive mode.
//DTurns on the debugger.
//E:engineExecutes the script with the specified script engine.
//H:CScript or //H:WscriptRegisters CScript.exe or WScript.exe as the default application for running scripts. If neither is specified, WScript.exe is assumed as the default.
//IDefault. Interactive mode; allows display of user prompts and script errors Opposite of Batch mode.
//Job:<JobID>Runs the specified JobID from the .wsf file.
//logoDefault. Displays a banner. Opposite of nologo.
//nologoPrevents display of an execution banner at run time. Default is logo.
//SSaves the current command-line options for this user.
//T:nnEnables time-out: the maximum number of seconds the script can run. The default is no limit. The //T parameter prevents excessive execution of scripts by setting a timer. When execution time exceeds the specified value, CScript interrupts the script engine using the IActiveScript::InterruptThread method and terminates the process.
//UUsed with Windows NT and Windows 2000 to force the command line output to be in Unicode. There is no way for CScript to determine whether to output in Unicode or ANSI; it defaults to ANSI.
//XLaunches the program in the debugger.
//?Displays a brief description of and usage information for command parameters (the usage information).