A WSF file is a script that fall under the executable category and commonly used in Microsoft Windows. The script supports the mixing of multiple languages, it means that in WSF file may include a blend of JScript, VBScript and optionally some XML elements or other scripting languages such as Python, Object REXX, Perl, Kixtart if installed by the user. The WSF files executes themselves in the absence of WScript or CScript. The WSF files can be beneficial in error isolation and exposing constants.
WSF file format
The WSF file format can mix the JScript and VBScript from your previous Windows Script Host projects, a .wsf file allows you to use them with Windows Script Host. A WSF script encapsulates a library of functions that can be used by various WSF files. The example below shows a .wsf file that includes a JScript file (fso.js), plus a VBScript function that calls another function.
<script language="JScript" src="FSO.JS"/>
' Get the free space for drive C.
s = GetFreeSpace("c:")
WSF format supports the following additional features:
Multiple jobs in one file
Benifits of WSF files
The WSF files can be beneficial in the following areas:
The modular nature of WSF file can prevents one script reference from interfering with another which makes the WSF useful for isolating errors. Here is an example of WSF with one module that produces an error and one that does not:
<?xml version="1.0" ?>
<job id="Partially works">
<!-- This will not work -->
WScript.echo 4/0 ' Oh, boy! You cannot divide by zero...
<!-- This will work... definitely... -->
WScript.echo "Hello, Scripters!" & vbNewline & _
"Fantastic! It worked!"
Mixed language support
A WSF supports multiple languages, you can have one scripting language use code from another scripting language. Here is an example of how that works:
The WSF support the binding of an XML wrapper to an object reference or control so you can use that object’s constants instead of having to declare them. Following is an example:
<?xml version="1.0" ?>
<!-- WSF Example with Object Reference
Notes for this very formal example:
CDATA is used to help the XML parser ignore
special characters in the content of the script.
The CDATA open and close must be masked
from VBScript by making them comments.
<reference object="ADODB.Recordset" />
dim title, str, i
ctecArray = Array("adOpenUnspecified","adOpenForwardOnly", _
title = "ADO Recordset Values for Constants"
str = title & vbNewLine & vbNewLine
str = str & "*CursorTypeEnum Constants*" & vbNewLine
For i = 0 to ubound(ctecArray)
str = str & Eval(ctecArray(i)) & vbTab & ctecArray(i) & vbNewLine
str = str & vbNewLine
str = str & "*LockTypeEnum Constants*" & vbNewLine
ltecArray = Array("adLockUnspecified","adLockReadOnly", _
For i = 0 to ubound(ltecArray)
str = str & Eval(ltecArray(i)) & vbTab & ltecArray(i) & vbNewLine
MsgBox str, vbInformation, Title