Introduction
- JobScheduler branch 1.x (JS1) supports scripting languages to which the JobScheduler Job API is exposed.
- The scripting languages JScript and VBScript are supported by the JVM on Windows 32bit systems only as they have never been ported for use with a 64bit JVM, see VBScript Jobs. The ScriptControl:VBScript job type introduced with JobScheduler release 1.10 acts as a replacement for VBScript jobs.
Running VBScript in JS1
A VBScript job in JS1 can look like this:
<job> <script language="VBScript"><![CDATA[function spooler_process() spooler_log.info( "hello world" ) spooler_process = false end function ]]></script> <run_time/> </job>
Explanation:
- The job can be executed with a Master or with an Agent.
- The job implements the
spooler_process()
callback function that is triggered by the Master or Agent. - As an alternative to script code being added directly to the job, users can apply
<include>
elements to reference files containing VBScript code (.vbs)..
<job process_class="/agent_windows"> <script language="scriptcontrol:vbscript"><![CDATA[function spooler_process() spooler_log.info( "hello world" ) spooler_process = false end function ]]></script> <run_time/> </job>
Explanation:
- The job can be executed with Agents only.
- The
scriptcontrol:vbscript
job type allows execution of the job provided that the Agent is running for a 32bit JVM.
Running VBScript in JS7
VBScript jobs and JScript jobs can be executed from a shell job in JS7 using the cscript.exe
utility provided by the Windows operating system.
The cscript.exe
utility can be parameterized with the path to a Windows Script File (.wsf) that
- includes references to files (.vbs) including VBScript code and/or
- directly includes VBScript code.
Therefore the migration of JS1 VBScript jobs to JS7 includes the steps to run cscript.exe
from a job and to provide a Windows Script File (.wsf) that holds references to VBScript files (.vbs).
Command for execution with a Job
The command in a JS7 job to execute VBScript can look like this:
cscript.exe //NoLogo C:\tmp\test.wsf
Explanation:
- The
cscript.exe
utility is executed with the//NoLogo
switch to suppress unwanted output to stdout. - The path to the Windows Script File
c:\tmp\test.wsf
is used as a parameter.
There could be reasons why to execute VBScript code in 32bit context, e.g. if the code makes references to the 32bit Windows Registry. In this situation modify the command like this:
%WINDIR%\SysWOW64\cmd.exe /k cscript.exe //NoLogo C:\tmp\test.wsf
Explanation:
- The only difference to the previous example is the use of
%WINDIR%\SysWOW64\cmd.exe /k
that precedes the call to thecscript.exe
utility. - This will create a 32bit bit Windows Shell and will run the
cscript.exe
utility in this context.
Windows Script File
A Windows Script File is an XML file that includes references to files (.vbs) holding VBScript code:
<?xml version="1.0" ?> <job id="none"> <script language="VBScript" src="c:\tmp\JS7_SpoolerClasses.vbs"/> <script language="VBScript" src="c:\tmp\test_01_include1.vbs"/> <script language="VBScript" src="c:\tmp\test_01_include2.vbs"/> <script language="VBScript" src="c:\tmp\test_01.vbs"/> </job>
Explanation:
- Any number of <script> elements can be used.
- Typically the last file included holds the start code.
Compatibility Functions for VBScript Jobs
Should VBScript jobs in JS1 have used the JobScheduler Job API, e.g. for logging purposes and to read parameters then they have to be migrated.
Users can modify the code to apply VBScript replacement functions or they can create a compatibility class that implements the Job API calls used in VBScript code of jobs.
Use of VBScript Replacement Functions
Users can check for native VBScript functions as a replacement for JS1 API methods like this:
Logging
- JS1 VBScript Job function call:
spooler_log.info( "hello world" )
- Native VBScript function call:
WScript.StdOut.WriteLine "hello world"
- JS1 VBScript Job function call:
- Parameters
- JS1 VBScript Job function call:
spooler_task.params( "some_parameter" )
- Native VBScript function call:
wshShell.ExpandEnvironmentStrings( "%SOME_PARAMETER%" )
- JS7 provides job arguments from environment variables.
- JS1 VBScript Job function call:
Use of a VBScript Compatibility Class
If the number of JS1 Job API methods used in VBScript code is somewhat limited then a VBScript class can be created that implements compatible methods and properties such as
spooler_log.info()
spooler_task.prams()
spooler_task.changed_directories()
spooler_job.order_queue
The implementation of the compatibility class can look like this:
Explanation:
- A number of classes are provided to implement e.g. the
spooler_log.info()
method. - The
spooler_log
object and similar objects are created when including the class file.