MDT Scripting: Installing an application

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
Advertisements

About Andrew Barnes

A Scripting and Deployment Specialist.
This entry was posted in MDT 2010, SCCM, Scripting and tagged , . Bookmark the permalink.

10 Responses to MDT Scripting: Installing an application

  1. ZeusABJ says:

    Hi Andrew,

    I have tried using this script but I get an “unexpected return code: 1” every time. Any ideas?

    Like

  2. Hi Andrew,

    Not sure to understand, you put your sources in \\DS\Script\SourceFiles? Why didn’t you leave your sources in the application folder?

    Like

    • This article is just for demonstration purposes. A single use deployment script should be build as a package/application. General scripts should be stored in the deployment share with the prefix ZTI so the replication will pick it up.

      Like

      • Shweta says:

        Hello Andrew,

        Could you please elaborate on this, i have created a application but it returns error code 14 which Intel non standard installer code stating success but reboot required.
        To avoid this i am using the above script provided by you to suppress the error code.
        I have saved the script as ZTI-Install-.wsf under DeploymentSHare\Scripts folder
        but how will i use path to teh exe under the application folder, is there is an FSO which can be used.

        Like

      • It sounds like your command line for your install is wrong. Work on that from a command prompt then move the tested command line back into the script.

        Like

  3. Michael Fonteyn says:

    Hello Andrew,

    many thanx for script.

    I have a question about more than one parameter in the command line. I am using the following:

    iRetVal = oShell.Run(“””” & sFile & “”” /s /pACTIVATIONCODE=” & oEnvironment.Item(“KasperskyLicenseText”) & ” /pKLPASSWD=Test123456 /pKLPASSWDAREA=SET;EXIT;UNINST”, 0, True)

    to deploy a Kaspersky Antivirus 2013 package, but problem is /pKLPASSWDAREA=SET;EXIT;UNINST. After installtion the passwordarea is not set, so i think my parameter are not working. I am not sure if a set it corectly with ; (semicolon). Do you have a solution?

    regards Michael Fonteyn

    Like

  4. DJ says:

    Hi, I am using SLShareDynamicLogging and SLShare in my CustomSettigns.ini configuration files. How can I go about directing the Application installation success and failure logs to these central log file shares? Thanks.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s