Deployment Script: Oracle Java Runtime 1.7.0.45

Topics: Archive - Deployment Scripts
Coordinator
Oct 29, 2013 at 3:36 PM
Here is an example deployment script of the Oracle Java Runtime 1.7.0.45. This will do the following:
  • Ensure Internet Explorer, Firefox and Chrome are all closed
  • Remove any previous version of the JRE (v6 and v7)
  • Install the JRE (highly advisable to customise using an MST to disable things like auto-update)
  • Disables the Java Expiration warning (which was introduced in JRE 7u30)
To use, just extract the JRE MSI to the Files folder.
<#
.SYNOPSIS
    This script performs the installation or uninstallation of an application(s).  
.DESCRIPTION
    The script is provided as a template to perform an install or uninstall of an application(s). 
    The script either performs an "Install" deployment type or an "Uninstall" deployment type.
    The install deployment type is broken down in to 3 main sections/phases: Pre-Install, Install, and Post-Install.
    The script dot-sources the AppDeployToolkitMain.ps1 script which contains the logic and functions required to install or uninstall an application.
    To access the help section,
.EXAMPLE
    Deploy-Application.ps1
.EXAMPLE
    Deploy-Application.ps1 -DeploymentType "Silent"
.EXAMPLE
    Deploy-Application.ps1 -AllowRebootPassThru -AllowDefer
.EXAMPLE
    Deploy-Application.ps1 -Uninstall 
.PARAMETER DeploymentType
    The type of deployment to perform. [Default is "Install"]
.PARAMETER DeployMode
    Specifies whether the installation should be run in Interactive, Silent or NonInteractive mode.
    Interactive = Default mode
    Silent = No dialogs
    NonInteractive = Very silent, i.e. no blocking apps. Noninteractive mode is automatically set if an SCCM task sequence or session 0 is detected.
.PARAMETER AllowRebootPassThru
    Allows the 3010 return code (requires restart) to be passed back to the parent process (e.g. SCCM) if detected from an installation. 
    If 3010 is passed back to SCCM a reboot prompt will be triggered.
.NOTES
.LINK 
    Http://psappdeploytoolkit.codeplex.com
"#>
Param (
    [ValidateSet("Install","Uninstall")] 
    [string] $DeploymentType = "Install",
    [ValidateSet("Interactive","Silent","NonInteractive")]
    [string] $DeployMode = "Interactive",
    [switch] $AllowRebootPassThru = $false
)

#*===============================================
#* VARIABLE DECLARATION
Try {
#*===============================================

#*===============================================
# Variables: Application

$appVendor = "Oracle"
$appName = "Java Runtime Environment"
$appVersion = "1.7.0.45"
$appArch = "x86"
$appLang = "EN"
$appRevision = "01"
$appScriptVersion = "1.0.0"
$appScriptDate = "10/29/2013"
$appScriptAuthor = "Dan Cunningham"

#*===============================================
# Variables: Script - Do not modify this section

$deployAppScriptFriendlyName = "Deploy Application"
$deployAppScriptVersion = "3.0.6"
$deployAppScriptDate = "10/07/2013"
$deployAppScriptParameters = $psBoundParameters

# Variables: Environment
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition
# Dot source the App Deploy Toolkit Functions
."$scriptDirectory\AppDeployToolkit\AppDeployToolkitMain.ps1"

#*===============================================
#* END VARIABLE DECLARATION
#*===============================================

#*===============================================
#* PRE-INSTALLATION
If ($deploymentType -ne "uninstall") { $installPhase = "Pre-Installation"
#*===============================================

    # Show Welcome Message, close web browsers if required, and verify there is enough disk space to complete the install
    Show-InstallationWelcome -CloseApps "iexplore,chrome,firefox" -CheckDiskSpace -PersistPrompt

    # Show Progress Message (with the default message)
    Show-InstallationProgress

    # Uninstall any previous JRE version
    Remove-MSIApplications "Java(TM) 6 Update"
    Remove-MSIApplications "Java 7 Update"
    
#*===============================================
#* INSTALLATION 
$installPhase = "Installation"
#*===============================================

    # Perform installation tasks here
    Execute-MSI -Action Install -Path "jre1.7.0_45.msi"

#*===============================================
#* POST-INSTALLATION
$installPhase = "Post-Installation"
#*===============================================

    # Disable Java Expiration warning (JRE 7u30+)
    Add-Content "$envUserProfile\AppData\LocalLow\Sun\Java\Deployment\deployment.properties" "deployment.expiration.check.enabled=false" -ErrorAction SilentlyContinue
 
#*===============================================
#* UNINSTALLATION
} ElseIf ($deploymentType -eq "uninstall") { $installPhase = "Uninstallation"
#*===============================================

    # Show Welcome Message, close web browsers if required with a 60 second countdown before automatically closing
    Show-InstallationWelcome -CloseApps "iexplore,chrome,firefox" -CloseAppsCountdown "60"

    # Show Progress Message (with the default message)
    Show-InstallationProgress

    # Perform uninstallation tasks here
    Execute-MSI -Action Uninstall -Path "jre1.7.0_45.msi"

#*===============================================
#* END SCRIPT BODY
} } Catch {$exceptionMessage = "$($_.Exception.Message) `($($_.ScriptStackTrace)`)"; Write-Log "$exceptionMessage"; Show-DialogBox -Text $exceptionMessage -Icon "Stop"; Exit-Script -ExitCode 1} # Catch any errors in this script 
Exit-Script -ExitCode 0 # Otherwise call the Exit-Script function to perform final cleanup operations
#*===============================================
Jul 3, 2014 at 10:54 PM
Edited Jul 4, 2014 at 7:02 PM
Hello

I would like like to install both x86 and x64 versions of Java on OSx64 and x86 on OSx86 with a single SCCM package. I'm assuming I could use the following to detect the OS.

# Perform installation tasks here
If ($psArchitecture -eq "x64") {
Show-InstallationProgress "Installing Java 7 Update 60 x64. Please wait..."
Execute-MSI -Action Install -Path "$dirFiles\jre1.7.0_60_x64\jre1.7.0_60.msi" -Parameters "TRANSFORMS=jre1.7.0_60_x64.mst /qn /norestart"
Show-InstallationProgress "Installing Java 7 Update 60 x86. Please wait..."
Execute-MSI -Action Install -Path "$dirFiles\jre1.7.0_60\jre1.7.0_60.msi" -Parameters "TRANSFORMS=jre1.7.0_60_x32.mst /qn /norestart"
}

ElseIf ($psArchitecture -eq "x86") {
Show-InstallationProgress "Installing Java 7 Update 60 x86. Please wait..."
Execute-MSI -Action Install -Path "$dirFiles\jre1.7.0_60\jre1.7.0_60.msi" -Parameters "TRANSFORMS=jre1.7.0_60_x32.mst /qn /norestart"
}

I have added 2 folders ( jre1.7.0_60 and jre1.7.0_60_x64) to the Files directory in the toolkit. I needed to use the -Parameters switch.

Update... I think I got it figured out. The code above is what worked for me.

Thanks
Jul 9, 2014 at 3:35 AM
Thanks for sharing.
Jul 29, 2014 at 10:12 PM
Edited Jul 29, 2014 at 10:13 PM
This one suppresses autoupdate, hide tray icons, silent install and other cool stuff. Java Update 765


<#
.SYNOPSIS
This script performs the installation or uninstallation of an application(s).  
.DESCRIPTION
The script is provided as a template to perform an install or uninstall of an application(s). 
The script either performs an "Install" deployment type or an "Uninstall" deployment type.
The install deployment type is broken down in to 3 main sections/phases: Pre-Install, Install, and Post-Install.
The script dot-sources the AppDeployToolkitMain.ps1 script which contains the logic and functions required to install or uninstall an application.
To access the help section,
.EXAMPLE
Deploy-Application.ps1
.EXAMPLE
Deploy-Application.ps1 -DeploymentType "Silent"
.EXAMPLE
Deploy-Application.ps1 -AllowRebootPassThru -AllowDefer
.EXAMPLE
Deploy-Application.ps1 -Uninstall 
.PARAMETER DeploymentType
The type of deployment to perform. [Default is "Install"]
.PARAMETER DeployMode
Specifies whether the installation should be run in Interactive, Silent or NonInteractive mode.
Interactive = Default mode
Silent = No dialogs
NonInteractive = Very silent, i.e. no blocking apps. Noninteractive mode is automatically set if an SCCM task sequence or session 0 is detected.
.PARAMETER AllowRebootPassThru
Allows the 3010 return code (requires restart) to be passed back to the parent process (e.g. SCCM) if detected from an installation. 
If 3010 is passed back to SCCM a reboot prompt will be triggered.
.NOTES
.LINK
Http://psappdeploytoolkit.codeplex.com
"#>
Param (
[ValidateSet("Install","Uninstall")] 
[string] $DeploymentType = "Install",
[ValidateSet("Interactive","Silent","NonInteractive")]
[string] $DeployMode = "Interactive",
[switch] $AllowRebootPassThru = $false
)

*===============================================

* VARIABLE DECLARATION

Try {

*===============================================

*===============================================

Variables: Application

$appVendor = "Oracle"
$appName = "Java Runtime Environment"
$appVersion = "1.7.0_65"
$appArch = "x86"
$appLang = "EN"
$appRevision = "01"
$appScriptVersion = "1.0.0"
$appScriptDate = "07/28/2014"
$appScriptAuthor = "Whatever"

*===============================================

Variables: Script - Do not modify this section

$deployAppScriptFriendlyName = "Java Update 7u65"
$deployAppScriptVersion = "1/0"
$deployAppScriptDate = "07/28/2014"
$deployAppScriptParameters = $psBoundParameters

Variables: Environment

$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition

Dot source the App Deploy Toolkit Functions

."$scriptDirectory\AppDeployToolkit\AppDeployToolkitMain.ps1"

*===============================================

* END VARIABLE DECLARATION

*===============================================

*===============================================

* PRE-INSTALLATION

If ($deploymentType -ne "uninstall") { $installPhase = "Pre-Installation"

*===============================================

# Show Welcome Message, close web browsers if required, and verify there is enough disk space to complete the install
Show-InstallationWelcome -CloseApps "iexplore,chrome,firefox" -CheckDiskSpace -PersistPrompt

# Show Progress Message (with the default message)
Show-InstallationProgress "Do not open any browsers doing so will probably make this installation fail. Call Jose @ x4524 if you have any problems with the java installation."
Show-BalloonTip "Please do not open any browsers during the installation!" -BalloonTipTitle "Updating Java"
# Uninstall any previous JRE version
Remove-MSIApplications "Java(TM) 6 Update"
Remove-MSIApplications "Java 7 Update"

*===============================================

* INSTALLATION

$installPhase = "Installation"

*===============================================

Show-InstallationProgress "We appreciate your time. Remember do not open any browsers. "
# Perform installation tasks here

Execute-MSI -Action Install -Path "jre1.7.0_65.msi" -Parameters "SPONSORS=0 ALLUSERS=1 JAVAUPDATE=0 AUTOUPDATECHECK=0 REBOOT=REALLYSUPPRESS WEBSTARTICON=0 SYSTRAY=0   /qn" 

*===============================================

* POST-INSTALLATION

$installPhase = "Post-Installation"

*===============================================

# Disable Java Expiration warning (JRE 7u30+)
Add-Content "$envUserProfile\AppData\LocalLow\Sun\Java\Deployment\deployment.properties" "deployment.expiration.check.enabled=false" -ErrorAction SilentlyContinue

*===============================================

* UNINSTALLATION

} ElseIf ($deploymentType -eq "uninstall") { $installPhase = "Uninstallation"

*===============================================

# Show Welcome Message, close web browsers if required with a 60 second countdown before automatically closing
Show-InstallationWelcome -CloseApps "iexplore,chrome,firefox" -CloseAppsCountdown "60"

# Show Progress Message (with the default message)
Show-InstallationProgress
Show-BalloonTip "Thank you for your patience" -BalloonTipTitle "Installation Completed"
# Perform uninstallation tasks here
Execute-MSI -Action Uninstall -Path "jre1.7.0_65.msi"

*===============================================

* END SCRIPT BODY

} } Catch {$exceptionMessage = "$($_.Exception.Message) ($($_.ScriptStackTrace))"; Write-Log "$exceptionMessage"; Show-DialogBox -Text $exceptionMessage -Icon "Stop"; Exit-Script -ExitCode 1} # Catch any errors in this script
Exit-Script -ExitCode 0 # Otherwise call the Exit-Script function to perform final clean-up operations

*===============================================

Aug 8, 2014 at 12:49 PM
Edited Aug 8, 2014 at 12:52 PM
Here is my version (with my ZAP MSI Applications Extensions
#*===============================================
#* VARIABLE DECLARATION
Try {
#*===============================================

#*===============================================
# Variables: Application

$appVendor = "Oracle"
$appName = "Java Runtime Environment"
$appVersion = "1.7.0.65"
$appArch = "x86"
$appLang = "EN"
$appRevision = "01"
$appScriptVersion = "1.0.0"
$appScriptDate = "7/21/2014"
$appScriptAuthor = "Richard Tracy"
#*===============================================
# Variables: Script - Do not modify this section

$deployAppScriptFriendlyName = "Deploy Application"
$deployAppScriptVersion = "3.0.6"
$deployAppScriptDate = "7/21/2014"
$deployAppScriptParameters = $psBoundParameters

# Variables: Environment
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition
# Dot source the App Deploy Toolkit Functions
."$scriptDirectory\AppDeployToolkit\AppDeployToolkitMain.ps1"
."$scriptDirectory\AppDeployToolkit\AppDeployToolkitExtensions.ps1"

#*===============================================
#* END VARIABLE DECLARATION
#*===============================================

#*===============================================
#* PRE-INSTALLATION
If ($deploymentType -ne "uninstall") { $installPhase = "Pre-Installation"
#*===============================================
    Clear-Variable Java*

    # Show Welcome Message, close web browsers if required, and verify there is enough disk space to complete the install
    Show-InstallationWelcome -CloseApps "jusched.exe,java.exe,jqs.exe,javacpl.exe,javaw.exe,iexplore.exe" -CheckDiskSpace -PersistPrompt
    $Java6x64Installed = $false
    $Java7x64Installed = $false
    # $Java7SDKInstalled = $false

    $Java2ProductNames = Get-InstalledApplication "Java 2"
    $Java6ProductNames = Get-InstalledApplication "Java(TM) 6"
    $Java7ProductNames = Get-InstalledApplication "Java 7"
    # $JavaSDK1ProductNames = Get-InstalledApplication "Java SE"
    # $JavaSDK2ProductNames = Get-InstalledApplication "Java(TM) SE"    

    # Uninstall any previous JRE version."  
    If ($JavaAUProductNames) {
        Foreach($JavaAUProductName in $JavaAUProductNames) {
            Show-InstallationProgress "Uninstalling $($JavaAUProductName.DisplayName)"
            Remove-MSIApplications $JavaAUProductName.DisplayName
            Zap-MSIApplication $JavaAUProductName.DisplayName
        }
    }

    If ($Java2ProductNames) {
        Foreach($Java2ProductName in $Java2ProductNames) {
            Show-InstallationProgress "Uninstalling $($Java2ProductName.DisplayName)"
            Remove-MSIApplications $Java2ProductName.DisplayName
            Zap-MSIApplication $Java2ProductName.DisplayName
        }
    }

    If ($Java6ProductNames) {
        Foreach($Java6ProductName in $Java6ProductNames) {
            If ($Java6ProductName -like "*64-bit*"){ $Java6x64Installed = $true}
            Show-InstallationProgress "Uninstalling $($Java6ProductName.DisplayName)"
            Remove-MSIApplications $Java6ProductName.DisplayName
            Zap-MSIApplication $Java6ProductName.DisplayName
        }
    }

    If ($Java7ProductNames) {
        Foreach($Java7ProductName in $Java7ProductNames) {
            If ($Java7ProductName -like "*64-bit*"){ $Java7x64Installed = $true}
            Show-InstallationProgress "Uninstalling $($Java7ProductName.DisplayName)"
            Remove-MSIApplications $Java7ProductName.DisplayName
            Zap-MSIApplication $Java7ProductName.DisplayName
        }
    }

    $JavaAUProductNames = Get-InstalledApplication "Java Auto Updater"
    If ($JavaAUProductNames) {
        Foreach($JavaAUProductName in $JavaAUProductNames) {
            Show-InstallationProgress "Uninstalling $($JavaAUProductName.DisplayName)"
            Remove-MSIApplications $JavaAUProductName.DisplayName
            Zap-MSIApplication $JavaAUProductName.DisplayName
        }
    }
    
#*===============================================
#* INSTALLATION 
$installPhase = "Installation"
#*===============================================
    $CopyYesNo = $true
    $JavaVersion = "jre1.7.0_65"
    $JavaCopyPath = "$envAllUsersProfile\Sun\Java"
    $InstallParameters = "EULA=1 IEXPLORER=1 JU=0 JAVAUPDATE=0 AUTOUPDATECHECK=0 LAUNCHBROWSER=False RebootYesNo=No /QN /norestart"

    # Perform installation tasks here
    Show-InstallationProgress "Installing Java 7 Update 65. Please wait..."
    If ($CopyYesNo) {
        New-Folder -Path $JavaCopyPath\$JavaVersion
        Copy-File -Path "$dirFiles\$JavaVersion\$JavaVersion.msi" -Destination "$JavaCopyPath\$JavaVersion\$JavaVersion.msi" -ContinueOnError $false
        Copy-File -Path "$dirFiles\$JavaVersion\Data1.cab" -Destination "$JavaCopyPath\$JavaVersion\Data1.cab"
        Execute-MSI -Action Install -Path "$JavaCopyPath\$JavaVersion\$JavaVersion.msi" -Parameters $InstallParameters
    }
    Else {
        Execute-MSI -Action Install -Path "$JavaCopyPath\$JavaVersion\$JavaVersion.msi" -Parameters $InstallParameters
    }

    If ($Java6x64Installed -or $Java7x64Installed) {
    Show-InstallationProgress "Installing Java 7 Update 65 (64-bit). Please wait..."
        If ($CopyYesNo) {
            New-Folder -Path ("$JavaCopyPath\$JavaVersion" + "_x64")
            Copy-File -Path ("$dirFiles\$JavaVersion" + "_x64\$JavaVersion.msi") -Destination ("$JavaCopyPath\$JavaVersion" + "_x64\$JavaVersion.msi")
            Copy-File -Path ("$dirFiles\$JavaVersion" + "_x64\Data1.cab") -Destination ("$JavaCopyPath\$JavaVersion" + "_x64\Data1.cab")
            Execute-MSI -Action Install -Path ("$JavaCopyPath\$JavaVersion" + "_x64\$JavaVersion.msi") -Parameters $InstallParameters
        }
        Else {
            Execute-MSI -Action Install -Path ("$JavaCopyPath\$JavaVersion" + "_x64\$JavaVersion.msi") -Parameters $InstallParameters
        }
    } 

#*===============================================
#* POST-INSTALLATION
$installPhase = "Post-Installation"
#*===============================================

    # Disable Java Expiration warning (JRE 7u30+)
    $JavaDepPath = "$envWinDir\Sun\Java\Deployment"
    New-Folder -Path $JavaDepPath
    Copy-File -Path "$dirSupportFiles\deployment.properties" -Destination "$JavaDepPath\deployment.properties"
    Copy-File -Path "$dirSupportFiles\deployment.config" -Destination "$JavaDepPath\deployment.config"
    Copy-File -Path "$dirSupportFiles\exception.sites" -Destination "$JavaDepPath\exception.sites"
    Execute-Process -FilePath "$envWinDir\system32\cmd.exe" -Arguments "/c regedit.exe /s ""$dirSupportFiles\javapolicy.reg""" -WindowStyle Hidden
       
#*===============================================
#* UNINSTALLATION
} ElseIf ($deploymentType -eq "uninstall") { $installPhase = "Uninstallation"
#*===============================================

    # Show Welcome Message, close web browsers if required with a 60 second countdown before automatically closing
    Show-InstallationWelcome -CloseApps "jusched.exe,java.exe,jqs.exe,javacpl.exe,javaw.exe,iexplore.exe" -CloseAppsCountdown "60"

    # Show Progress Message (with the default message)
    Show-InstallationProgress

    # Perform uninstallation tasks here
    $Java6x64Installed = $false
    $Java7x64Installed = $false

    # Uninstall"  
    $Java7ProductNames = Get-InstalledApplication "Java 7"
    If ($Java7ProductNames) {
        Foreach($Java7ProductName in $Java7ProductNames) {
            If ($Java7ProductName -like "*64-bit*"){ $Java7x64Installed = $true}
            Show-InstallationProgress "Uninstalling $($Java7ProductName.DisplayName)"
            Remove-MSIApplications $Java7ProductName.DisplayName
            Zap-MSIApplication $Java7ProductName.DisplayName
        }
    }
We make this available to all systems so users can run it when needed. This script also detects if java 64 bit is available and fix it too if needed. The problem is if the user run the uninstall, it uninstalls both, then only install non 64 bit.