BDD provides a scripting framework, by leveraging this framework you can write a custom script that can utilize the functionality that BDD provides. This functionality includes a logging, accessing and changing environment variables and a number of utility functions.
Before describing how to create a script it is best to review how the scripts included with BDD are constructed.
The standard BDD script is a WSF file, this allows references to be made to functions that are contained in other scripts. BDD scripts leverage this functionality by referencing a script called “ZTIUtility.vbs”.
Understanding ZTIUtility.vbs
ZTIUtility.vbs is used to initialize the BDD environment and setup classes, these can then be used by scripts that reference it.
The script defines a number of standard objects:
Note: You do not need to declare these objects in your script.
Four classes are defined which perform a number of standard tasks:
These classes can be referenced in your scripts, here are some examples for each of the classes:
Environment class
This class is referenced in scripts through the object “oEnvironment”.
For example you change the computer name to “Blah” using the following command:
oEnvironment.Item("ComputerName") = “Blah”
Or if you needed to determine if this is an x86 or x64 then you could query the architecture using the following command:
oEnvironment.Item("Architecture")
Logging class
This class is referenced in scripts through the object “oLogging”.
When creating a informational log entry use the following command:
oLogging.CreateEntry "Informational message", LogTypeInfo
When creating a error log entry use the following command:
oLogging.CreateEntry "An error occured“,LogTypeError
Utility class
The class is referenced in scripts through the object “oUtility”.
To determine the name of the the current script, use the following command:
oUtility.ScriptName
To find the location of a file and BDD use the following command will look in a number of locations for it.
iRetVal = oUtility.FindFile("CustomSettings.ini", sIniFile)
Database class
The class is referenced in scripts through the object “oDatabase”. There is generally no need to use the database class directly. Database lookups can be performed using rule processing. See my rule processing blog for more information.
This is a high level view of the tasks that ZTIUtility.vbs can perform. It is worthwhile taking a good look through the script yourself as there are many hidden gems.
Now that we have reviewed the framework lets look at how to write a custom script. I have created a script template below which is based on the structure used within the standard BDD scripts. The template is simply a wrapper that references the ZTIUtility.vbs script and launches the function "ZTIProcess". To create your own script you simply place your code within the ZTIProcess function.
Here is a quick overview of the steps required to add your script to a BDD build:
It is also important to remember the following key rules when creating your script:
Hopefully these tips will get you started, writing your own scripts that leverage the true flexibility of BDD.
Template
Use the following template to create your own custom scripts.
<job id="Z-Sample"><script language="VBScript" src="ZTIUtility.vbs" mce_src="ZTIUtility.vbs"/><script language="VBScript">
' //***************************************************************************' // ***** Script Header *****' //' // Solution: Solution Accelerator for Business Desktop Deployment' // File: Z-Sample.wsf' //' // Purpose: Template' //' // Usage: cscript Z-Sample.wsf [/debug:true]' //' // Customer Build Version: 1.0.0' // Customer Script Version: 1.0.0' // Customer History:' //' // ***** End Header *****' //***************************************************************************
'//----------------------------------------------------------------------------'//'// Global constant and variable declarations'//'//----------------------------------------------------------------------------
Option Explicit
Dim iRetVal
'//----------------------------------------------------------------------------'// End declarations'//----------------------------------------------------------------------------
'//----------------------------------------------------------------------------'// Main routine'//----------------------------------------------------------------------------
On Error Resume NextiRetVal = ZTIProcessProcessResults iRetValOn Error Goto 0
'//---------------------------------------------------------------------------'//'// Function: ZTIProcess()'//'// Input: None'// '// Return: Success - 0'// Failure - non-zero'//'// Purpose: Perform main ZTI processing'// '//---------------------------------------------------------------------------Function ZTIProcess()
iRetVal = Success
ZTIProcess = iRetval
'!!!!!!!!!!! INSERT YOUR CODE HERE !!!!!!!!!!!!
End Function
</script></job>
Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified in the Terms of Use.