How to Write VBScript using XML?

0
165
Spread the love
  • 28
  • 34
  • 56
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    165
    Shares

Write VBScript using XML
Write VBScript using XML

How to Write VBScript using XML?

WSH supports XML ( a case sensitive extended markup language to create a script and pass test data. XML tags can be used in Windows Script file are as follows:

Tags Meaning
<?xml?> It specifies windows script file’s XML level or version.
<?job?> It specifies to enable or disable error handling and debugging for a job.
<comment></comment> It enables us to embed comments within the script.
<Script></script> It defines a new script is being created.
<job></job> It defines a job .
<package></package> It configures multiple jobs to be defined in a single script file.
<resource></resource> It defines a static data that can be referenced by the script.

 

Let’s see the elements one by one

<?xml?>

<?xml?> is an optional tag that specifies XML version. This needs to be the first statement in the WSF if used. It does not need a closing tag.

Syntax

<?xml version="x.y" standalone="dfdflag"?>
  • Standalone refers to the boolean value which indicates if an external DTD (Document Type Definition) should be included or not.

Example

<?xml version="1.01" standalone="yes"?>

<?job?>

<?job?> is also an optional tag. It enables or disables error reporting and debugging. It does not need a closing tag.

Syntax

<?job error="errorflag" debug="defugflag"?>

errorflag and debugflag are boolean values.

If set true- error reporting will be enabled, false will disable error reporting. debugflag controls the presence of windows script debugger on an error. If set true, it will open Windows Script Debugger for the error. If set false it will not open Windows Script Debugger.

Example

<?job error="true" debug="true"?>

<comment></comment>

<comment></comment> tag enables us to put a comment in the script file. We can also use multi line comment with this tag.

Syntax

<comment>Our comment</comment>

Example

<comment>Our First comment</comment>

<script></script>

<script></script> enables us to write scripts. The scripts may be written in multiple languages(WSH supported languages).

Syntax

<script language="ScriptLanguage",[Src ="pathOfScript"]>
....
....
....
</script>

Where

  • ScriptLanguage is WSH approved language.
  • Src is an optional parameter. It just tells WSH where the script is located.

Example

<script language="VBScript">
msgbox "hello"
</script>
or
<script language="VBScript" Src="D:\scriptName.vbs">
</script>

<job></job>

WSF(Window Script File) may contain more than one job. And each job may contain more than one script. The jobs are defined inside <job></job> tag

Syntax

<job [id=myjobID]>
....
....
</job>

Where myjobID is the unique identifier to identify jobs in a WSF. If this parameter is omitted, it signifies that there is only one job in the script. JobID also helps us to specify which job we want to run.

Example

<job>
<script language="VBScript">
msgbox "hello"
</script>
<script language="jsScript">
Wscript.Echo("hello")
</script>
<script language="VBScript" Src="D:\hello.vbs">
</script>
</job>

<package></package>

<package></package> is useful when we want to place more than one jobs in the WSF.

Syntax

<package>
.....
.....
</package>

Example

<package>
<job id="myjob-1">
<script language="VBScript">
msgbox "hello"
</script>
</job>
<job id="myjob-2">
<script language="jsScript">
Wscript.Echo("hello")
</script>
</job>
<job id="myjob-3">
<script language="VBScript" Src="D:\hello.vbs">
</script>
</job>
</package>

<resource></resource>

<resource></resource> tag allows us to define constants that our script can access and use during execution time. This tag supports one or more constants. These constants can be defined once and can be used over and over.

<resource></resource> tag needs to be placed within <job></job> tag.

Syntax

<resource id="resourceID">
....
....
</resource>

resourceID is used to name the constant. The value of the constant is assigned in the tag itself.

Example

<resource id="oneDollar">70</resource>
<script language="VBscript"
msgbox "5$="& 5*getResource("oneDollar")
</script></job>

How to execute a WSF file created in XML?

To execute all jobs we need to fire the command

Wscript myScript.wsf // for all jobs

To execute the selected job we need to fire the below command

Wscript myScript.wsf //job:myJob-2
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 28
  • 34
  • 56
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    165
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here