Skip to end of metadata
Go to start of metadata

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:

Example for job to execute VBScript with "vbscript" job type
<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)..


Example for job to execute VBScript with "scriptcontrol:vbscript" job type
<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) containing VBScript code and/or
  • directly contains VBScript code.

Therefore the migration of JS1 VBScript jobs to JS7 includes running cscript.exe from a job and providing a Windows Script File (.wsf) that holds references to VBScript files (.vbs).

Command for execution with a Job

The command in a JS7 job which executes VBScript can look like this:

Example for command to execute VBScript in 64bit mode
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 for executing VBScript code in a 32bit context, e.g. if the code makes references to the 32bit Windows Registry. In this situation modify the command as follows:

Example for command to execute VBScript in 32bit mode
%WINDIR%\SysWOW64\cmd.exe /k cscript.exe //NoLogo C:\tmp\test.wsf

Explanation:

  • The difference to the previous example is the use of %WINDIR%\SysWOW64\cmd.exe /k that precedes the call to the cscript.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:

Example for a Windows Script File
<?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 holds the start code.

Compatibility Functions for VBScript Jobs

If VBScript jobs in JS1 have used the JobScheduler Job API, e.g. for logging purposes and reading 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"
  • 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.

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:

Compatibility Class for VBScript
Class SpoolerOrderQueue

    Public order_queue

    Public Function get_order_queue()
       get_order_queue = order_queue
    End Function

End Class


Class SpoolerJob

    Private wshShell
    Public order_queue

    Private Sub Class_Initialize()
        Dim result
        Set wshShell = CreateObject( "WScript.Shell" )

        If ( wshShell.ExpandEnvironmentStrings( "%JS7_ORDER_ID%" ) <> "%JS7_ORDER_ID%" ) Then
            set order_queue = new SpoolerOrderQueue
        Else
            set order_queue = Nothing
        End If
    End Sub

End Class


Class SpoolerLog

    Public Sub Info( message )
        WScript.StdOut.WriteLine message
    End Sub

End Class


Class SpoolerTask

    Private wshShell
    Public trigger_files    

    Private Sub Class_Initialize()
        Set wshShell = CreateObject( "WScript.Shell" )

        If ( wshShell.ExpandEnvironmentStrings( "%FILE%" ) <> "%FILE%" ) Then
            trigger_files = wshShell.ExpandEnvironmentStrings( "%FILE%" )
        Else
            trigger_files = vbNull
        End If
    End Sub

    Public Function Params( name )
        Dim result
        result = wshShell.ExpandEnvironmentStrings( "%" & UCase(name) & "%" )

        If ( result = "%" & UCase(name) & "%" ) Then
            Params = vbNull
        Else
            Params = result
        End If
    End Function

    Public Function Changed_Directories()
        Dim result
        result = wshShell.ExpandEnvironmentStrings( "%FILE%" )

        If ( result = "%FILE%" ) Then
            Changed_Directories = vbNull
        Else
            Changed_Directories = result
        End If
    End Function

End Class


Class SpoolerGlobal

    Private wshShell

    Private Sub Class_Initialize()
        Set wshShell = CreateObject( "WScript.Shell" )
    End Sub

    Public Function Variables( name )
        Dim result
        result = wshShell.ExpandEnvironmentStrings( "%" & UCase(name) & "%" )

        If ( result = "%" & UCase(name) & "%" ) Then
            Variables = vbNull
        Else
            Variables = result
        End If
    End Function

End Class


Set spooler_job = new SpoolerJob
Set spooler_log = new SpoolerLog
Set spooler_task = new SpoolerTask
Set spooler = new SpoolerGlobal

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.



  • No labels
Write a comment…