Todd Hemsell at myITforum.com

{Enter witty eye catching description here}

Microsoft Deployment Toolkit Wizard Editor : Part 2 : Global Settings and Custom Initialization and Validation scripts.

In my previous post Microsoft Deployment Toolkit Wizard Editor : Part 1 : Introduction we went  over what the WizardEditor was, and how to get the files and such required to begin editing a definition XML File. this post begins where that left off.

The first thing will will look at is the global settings.

The most common type of settings for global are CustomStatement, Initialization, and Validation.

image

A Custom statement will get executed by code in Wizard.hta (snippet below)

'Custom processing within a string
for each item in oXMLDoc.SelectNodes("//Wizard/Global/CustomStatement")
   if not ExecuteWithErrorHandling(ITem.TExt) then
      window.close
      exit sub
   end if
next

you can see it will call the function ExecuteWithErrorHandling. You will also notice that function does not exist in Wizard.hta, so where is it? it is in WizUtility.vbs, one of the resource files used by Wizard.hta. Wizard.hta loads WizUtility exposing all of the function in it to the code in the hta

image

WizUtility.vbs  it uses the ExecuteGlobal statement to execute the code in the custom statement.

Function ExecuteWithErrorHandling ( statements )
    Dim RunAgain
    RunAgain = FALSE

    On error resume Next
    Err.Clear
    ExecuteGlobal statements     
    ExecuteWithErrorHandling = err.number = 0   
    RunAgain = DisplayErrorIfAny (statements)
    On error goto 0
    If RunAgain then
        ExecuteGlobal statements
    End if

End function

So to sum up, you can execute any vbscript code you like, and use any function in either WizUtility or ZTIUtility without editing any of the scripts supplied in MDT just by putting the code into a CustomStatement in the Global section. This will allow you to customize your solution and be able to upgrade the scripts and such without needing to rewrite them all.

The “Initialization” setting is similiar to the CustomStatement because they both use ExecuteGlobal.

image

Here is how the Wizard uses the file(s) specified in Initialization section “ ExecuteWithErrorHandling(oFso.OpenTextFile(srootDir & Item.TExt ,ForReading,FALSE).ReadAll) ”. Essentially  it reads the entire vbs file and sends it to the ExecuteGlobal statement

the “Validation” statement in the global section does, as  far as I can tell, the exact same thing the Initialization section does. I cannot figure out why there are two different types. If you know please shoot me an email or leave a comment

image

So what is the significance of this? you can write your own vbscript with your own functions in it without modifying the MDT scripts.

Make a new vbscript file and put it in the directory with the rest of the sample files. I named mine DeployWiz_Validation_CUSTOM.vbs. then Make a new action of type initialization as shown below

image

Then set the name of the vbs file.

image

Next Post: Panes can be a pain, or how to bring external data into your wizard.

Comments

No Comments