Windows Script File | |
Extension: | .wsf |
Owner: | Microsoft |
Genre: | Scripting |
Container For: | Scripts |
A Windows Script File (WSF) is a file type used by the Microsoft Windows Script Host. It allows mixing the scripting languages JScript and VBScript within a single file, or other scripting languages such as Perl, Object REXX, Python, or Kixtart if installed by the user. These types of scripts may also be used to link many other external scripts together using a src
parameter on the tag in a manner similar to HTML. Windows Script Files have the extension ".WSF"
. A WSF makes reference to each script module in a very basic XML hierarchy as shown below, adhering to those standards outside the tags. Literal use of "" or "" inside your tags and similar challenges can be handled by the use of CDATA, as shown within the examples.
A WSF may be useful for isolating errors. Its modular nature prevents one script reference from interfering with another. Here is a WSF example with one module that produces an error and one that does not:
A Windows Script File supports multiple languages, as described on the Windows Script Host reference. One of the features of this file format is that you may use more than one at once. This means you can have one scripting language use code from another scripting language. The most memorable example for long-time VBScript users is the use of Microsoft JScript to service a sort request for VBScript since it does not have a built-in sort function for an array of values. VBScript users may write their own sort method or borrow one from an existing object like an ADO (ActiveX Data Objects) Recordset or a .NET (.NET Framework) ArrayList, but the fastest way to sort an array is to use the method built into JScript. Here is a basic example of how that works:
Another very useful feature of a WSF is that the XML wrapper can be bound to an object reference or control so you can use that object's constants instead of having to declare them. In regular VBScript and JScript files, you would be forced to declare a constant's value (outside those that are internal to the Windows Script Host) in order to use the constant. An example of this is shown below:".WSF"
extension, such as one named "EnumerateConstantsADO.wsf"
, will produce the result shown below:
-1 adOpenUnspecified0 adOpenForwardOnly1 adOpenKeyset2 adOpenDynamic3 adOpenStatic
-1 adLockUnspecified1 adLockReadOnly2 adLockPessimistic3 adLockOptimistic4 adLockBatchOptimisticIn addition, using the object reference to expose the constants makes writing the script more like writing in a standard programming language. In fact, the contents of the sample script, written in VBScript, will actually compile into a Visual Basic program and run the same way as long as that program uses the same reference to ADODB.