VBScript Tutorials - Herong's Tutorial Examples - Version 5.20, by Dr. Herong Yang

WSF - Windows Script File XML Format

This section describes the WSF (Windows Script File) XML format. Multiple script jobs with different scripting language can be defined in a single WSF file.

WSH can run a VBScript code file directly. But it also supports an XML file format called .WSF (Windows Script File). WSF file offers an XML structure to define script jobs and group jobs into a package.

WSF supports the following basic XML elements:

  • "package" - The root element of WSF file.
  • "package.job" - The job element defines a script job with the "id" attribute.
  • "package.job.script" - The script element inserts a segment of script code in the language specified in the "language" attribute.

Here is a tutorial example of a WSF file:

<?xml version="1.0" encoding="UTF-8"?>
<package>
<!-- Windows_Script_File.vbs
 - Copyright (c) 2015, HerongYang.com, All Rights Reserved.
-->
   <job id="VBScriptJob">
      <script language="VBScript">
         WScript.Echo "Hello world! - VBScriptJob"
      </script>
   </job>

   <job id="JScriptJob">
      <script language="JScript">
         WScript.Echo("Hello world! - JScriptJob"); 
      </script>
   </job>
   
   <job id="MixedJob">
      <script language="VBScript">
         Dim sName
         sName = "MixedJob"
      </script>
      <script language="JScript">
         WScript.Echo("Hello world! - "+sName); 
      </script>
   </job>
</package>

Jobs defined in this WSF file can be executed with WSH hosts as shown below:

C:\herong>cscript //Job:VBScriptJob Windows_Script_File.wsf

Hello world! - VBScriptJob

C:\herong>cscript //Job:JScriptJob Windows_Script_File.wsf

Hello world! - JScriptJob

C:\herong>cscript //Job:MixedJob Windows_Script_File.wsf

Hello world! - MixedJob

Note that:

  • "//Job:..." option must be used to run a job defined in a WSF file, except for the first job.
  • "JScript" is the Microsoft version of JavaScript.
  • "MixedJob" shows that multiple script code segments of different language can be used together to perform a single task.

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

 Arithmetic Operations

 Numeric Comparison Operations and Logical Operations

 String Operations - Concatenation and Comparison

 Variable Declaration and Assignment Statement

 Expression and Order of Operation Precedence

 Statement Syntax and Statement Types

 Array Data Type and Related Statements

 Array References and Array Assignment Statements

 Conditional Statements - "If ... Then" and "Select Case"

 Loop Statements - "For", "While", and "Do"

 "Function" and "Sub" Procedures

 Built-in Functions

 Inspecting Variables Received in Procedures

 Error Handling Flag and the "Err" Object

 Regular Expression Pattern Match and Replacement

 scrrun.dll - Scripting Runtime DLL Library

 Creating Your Own Classes

 IE Web Browser Supporting VBScript

 IIS ASP Server Supporting VBScript

WSH (Windows Script Host)

 What is WSH (Windows Script Host)?

 "csript.exe/wscript.exe" Command Version and Options

 Running VBScript Code Files

 "WScript" Runtime Object Hierarchy

 "oShell.Exec(cmd)" - Running System Command with a Script

WSF - Windows Script File XML Format

 References

 Printable Copy - PDF Version

WSF - Windows Script File XML Format - Updated in 2015, by Dr. Herong Yang