
Despite the name of the blog, so far I’ve done very little in the way of actual scripting so its not a wonder some of my readers think that this is just an MDT blog. The fact is I intend to cover many aspects of Windows Deployment over the next 12 months.
As a follow-up to my opening article about scripting using the MDT Script Template, this blog will focus on installing an application and demonstrate the power of the ZTIUtility. I forgot to mention in my last article that I uploaded the template in the Script Repository here so help yourselves. I’ve also uploaded todays script here.
The target application we wish to install today is Adobe Acrobat X. I have use the command line from AppDeploy here. First, lets take a look at the code:
<job id="Install-AdobeReaderX">
<script language="VBScript" src="ZTIUtility.vbs"/>
<script language="VBScript">
' //----------------------------------------------------------------------------
' //
' // Solution: Scriptimus Ex Machina - Deployment Script
' // File: Install-AdobeReaderX.wsf
' //
' // Purpose: This will install Install Adobe Reader X 10.x
' //
' // Author: Scriptimus Prime
' //
' // Usage: cscript Install-AdobeReaderX.wsf [/debug:true]
' //
' //----------------------------------------------------------------------------
'//----------------------------------------------------------------------------
'//
'// Global constant and variable declarations
'//
'//----------------------------------------------------------------------------
Option Explicit
Dim iRetVal
'//----------------------------------------------------------------------------
'// End declarations
'//----------------------------------------------------------------------------
'//----------------------------------------------------------------------------
'// Main routine
'//----------------------------------------------------------------------------
On Error Resume Next
iRetVal = ZTIProcess
ProcessResults iRetVal
On Error Goto 0
'//---------------------------------------------------------------------------
'//
'// Function: ZTIProcess()
'//
'// Input: None
'//
'// Return: Success - 0 or 3010
'// Failure - non-zero
'//
'// Purpose: Perform main ZTI processing
'//
'//---------------------------------------------------------------------------
Function ZTIProcess()
Dim sFile
oLogging.CreateEntry "INSTALL ADOBE READER X: Begin ADOBE READER X installation", LogTypeInfo
sFile = oUtlity.ScriptDir & "\SourceFiles\AdbeRdr1000_en_US.exe"
If not oFSO.FileExists(sFile) then
oLogging.CreateEntry "INSTALL ADOBE READER X " & sFile & " was not found, unable to install ADOBE READER X", LogTypeError
ZTIProcess = Failure
Exit Function
End if
oEnv("SEE_MASK_NOZONECHECKS") = 1
iRetVal = oShell.Run("""" & sFile & """ /sAll /rs /msi EULA_ACCEPT=YES", 0, True)
if (iRetVal = 0) or (iRetVal = 3010) then
ZTIProcess = Success
Else ZTIProcess = Failure
End If
oLogging.CreateEntry "INSTALL ADOBE READER X: Return code value = " & iRetVal, LogTypeInfo
oEnv.Remove("SEE_MASK_NOZONECHECKS")
oLogging.CreateEntry "INSTALL ADOBE READER X: Completed ADOBE READER X installation", LogTypeInfo
End Function
</script>
</job>
Ok, time to break it all down. I used the MDT Script template and changed the names etc. then in the main routine, I inserted my custom code.
First, we declare the variables just as we would in any normal Visual Basic Script except we only have to declare sFile as all the other variables have been declared for us in the ZTIUtility.vbs.
Dim sFile
Next, we use the ZTIUtililty Logging Class to create an entry in the log file to show that the installation has begun.
oLogging.CreateEntry "INSTALL ADOBE READER X: Begin ADOBE READER X installation", LogTypeInfo
We place the installation source file in a variable so we can re-use the value.
sFile = oUtlity.ScriptDir & "\SourceFiles\AdbeRdr1000_en_US.exe"
It’s important to test that the source files have not been moved or corrupted. This little routine takes care of that part. It uses the File Scripting Object method already defined in the ZTIUtility. so we can take advantage of it without having to set it up as usual. Also, we use the LogTypeError switch at the end of the logging class line.
If not oFSO.FileExists(sFile) then
oLogging.CreateEntry "INSTALL ADOBE READER X " & sFile & " was not found, unable to install ADOBE READER X", LogTypeError
ZTIProcess = Failure
Exit Function
End if
This time we use the ZTIUtility Environment Class to resolve a common scripting issue. There’s a widely known issue that when you try to use VBScript to run a program that has been downloaded it returns a security popup. It’s described in the Microsoft article KB889815 and you can read all about it here. In short this line will just disable all Zone Checking by setting the environment variable SEE_MASK_NOZONECHECKS to 1.
oEnv("SEE_MASK_NOZONECHECKS") = 1
This line is our run command and it uses the object shell method to execute the command line needed to install Adobe Reader X. The success/failure results are stored in the iRetVal variable.
iRetVal = oShell.Run("""" & sFile & """ /sAll /rs /msi EULA_ACCEPT=YES", 0, True)
This section will set the ZTIProcess variable to the value returned by the application installation. If a zero is returned 0 then the application has installed just fine. If the return value is 3010 then it has installed but a reboot is now required to complete the installation.
if (iRetVal = 0) or (iRetVal = 3010) then
ZTIProcess = Success
Else
ZTIProcess = Failure
End If
The Logging Class in this line creates the log entry stating the return value based on the information returned above.
oLogging.CreateEntry "INSTALL ADOBE READER X: Return code value = " & iRetVal, LogTypeInfo
As part of the winding up process, we will need to set the Zone Checking back to normal. We do that by removing the environment variable and value set earlier.
oEnv.Remove("SEE_MASK_NOZONECHECKS")
Finally, we create a log file entry to show that the installation process has ended. This uses the MDT Logging Class to create an entry.
oLogging.CreateEntry "INSTALL ADOBE READER X: Completed ADOBE READER X installation", LogTypeInfo