This project is read-only.

Java install on Windows 7 64 bit detection

Topics: Archive - General
Nov 5, 2014 at 1:42 PM
We have some Windows 7 64 bit machines that have Java 7 32 bit and some that have java 7 64 bit, and some that have both. I want to put application detection in my script. I think I have for 32 bit version but how would I get it for 64 bit detection as well?

Here is for 32 bit :

[version]$JavaVersion = Get-InstalledApplication "Java 7 Update" | select "DisplayVersion" -expand "DisplayVersion"

If ($JavaVersion -lt [version]"7.0.670.1" -or $JavaVersion -eq $null) {
 Execute-MSI -Action Install -Path "$dirFiles\x64\jre1.7.0_67.msi" -Parameters "SPONSORS=0 ALLUSERS=1 JAVAUPDATE=0 AUTOUPDATECHECK=0 REBOOT=REALLYSUPPRESS WEBSTARTICON=0 SYSTRAY=0   /qn"    
}
Nov 5, 2014 at 1:51 PM
actually the above wouldnt work either as I do not want installation to happen if java is not installed on the system....thoughts anyone?
Nov 5, 2014 at 3:10 PM
Never mind in order for this to install cleanly I need to remove existing first. I will just use a collection query and target necessary machines.
Nov 6, 2014 at 7:17 PM
Figured I will need this in my future installation scenarios.
So I modified Get-Installation to detect if it was installed in the 64-bit Registry Node.
Function Get-InstalledApplication {
<#
.SYNOPSIS
    Retrieves information about installed applications.
.DESCRIPTION
    Retrieves information about installed applications by querying the registry. You can specify an application name, a product code, or both.
    Returns information about application publisher, name & version, product code, uninstall string, install source, location & date.
.EXAMPLE
    Get-InstalledApplication -Name "Adobe Flash"
.EXAMPLE
    Get-InstalledApplication -ProductCode "{1AD147D0-BE0E-3D6C-AC11-64F6DC4163F1}"
.PARAMETER ApplicationName
    The name of the application you want to retrieve information on. Performs a wildcard match on the application display name.
.PARAMETER ProductCode
    The product code of the application you want to retrieve information on.
.NOTES
.LINK
    Http://psappdeploytoolkit.codeplex.com
#>
    Param (
        [array] $Name = "",
        [string] $ProductCode = ""
    )

    If ($name -ne "") { Write-Log "Getting information for installed Application Name [$name]..."}
    If ($productCode -ne "") { Write-Log "Getting information for installed Product Code [$ProductCode]..."}
    If ($name -eq "" -and $ProductCode -eq "") { Write-Log "Get-InstalledApplication Error: Please provide an Application Name or Product Code."; Return $null }
    # Replace special characters in product code that interfere with regex match
    $productCode = $productCode -replace "}","" -replace "{",""
    $applications = $name -split (",")
    # Replace special characters in application name that interfere with regex match
    $applications = $applications -replace "\.","dot" -replace "\*","asterix" -replace "\+","plus" -replace "\(","openbracket" -replace "\)","closebracket" -replace "\[","opensquarebracket" -replace "\]","closesquarebracket"
    $installedApplication = @()
    Foreach ($regKey in $regKeyApplications ) {
        If (Test-Path $regKey -ErrorAction SilentlyContinue) {
        $regKeyApplication = Get-ChildItem $regKey -ErrorAction SilentlyContinue | ForEach-Object { Get-ItemProperty -LiteralPath $_.PsPath }
            Foreach ($regKeyApp in $regKeyApplication) {
                $appDisplayName = $null
                $appDisplayVersion = $null
                $appPublisher = $null
                $appIn64Bit = $null
                # Bypass any updates or hotfixes
                If ([RegEx]::Match($regKeyApp.DisplayName, "(?i)kb\d+") -eq $true) { Continue }
                If ($regKeyApp.DisplayName -match "Cumulative Update") { Continue }
                If ($regKeyApp.DisplayName -match "Security Update") { Continue }
                If ($regKeyApp.DisplayName -match "Hotfix") { Continue }
                # Remove any non-standard characters from the name / version which may interfere with logging
                $appDisplayName = [RegEx]::Replace($regKeyApp.DisplayName, "[^\u001F-\u007F]", "")
                $appDisplayVersion = [RegEx]::Replace($regKeyApp.DisplayVersion, "[^\u001F-\u007F]", "")
                $appPublisher = [RegEx]::Replace($regKeyApp.Publisher, "[^\u001F-\u007F]", "")
                $appIn64Bit = If ($regKey -notmatch "Wow6432Node" -and $is64Bit -eq $true) {$true} Else {$False}
                If ($ProductCode -ne "") {
                    # Replace special characters in product code that interfere with regex match
                    $regKeyProductCode = $($regKeyApp.PSChildName) -replace "}","" -replace "{",""
                    # Verify if there is a match with the product code passed to the script
                    If ($regKeyProductCode -match $productCode) {
                        Write-Log "Found installed application [$($appDisplayName)] version [$($appDisplayVersion)] matching product code [$productCode]"
                        $installedApplication += New-Object PSObject -Property @{
                            ProductCode =       $regKeyApp.PSChildName
                            DisplayName =       $appDisplayName
                            DisplayVersion =    $appDisplayVersion
                            UninstallString =   $regKeyApp.UninstallString
                            InstallSource =     $regKeyApp.InstallSource
                            InstallLocation =   $regKeyApp.InstallLocation
                            InstallDate =       $regKeyApp.InstallDate
                            Publisher =         $appPublisher
                            x64RegistryKey =    $appIn64Bit
                        }
                    }
                }
                If ($name -ne "") {
                    # Verify if there is a match with the application name(s) passed to the script
                    Foreach ($application in $applications) {
                        If (($regKeyApp.DisplayName -replace "\.","dot" -replace "\*","asterix" -replace "\+","plus" -replace "\(","openbracket" -replace "\)","closebracket" -replace "\[","opensquarebracket" -replace "\]","closesquarebracket") -match $application ) {
                            Write-Log "Found installed application [$($appDisplayName)] version [$($appDisplayVersion)] matching application name [$application]"
                            $regKeyApp.DisplayName = $regKeyApp.DisplayName
                            $installedApplication += New-Object PSObject -Property @{
                                ProductCode =       $regKeyApp.PSChildName
                                DisplayName =       $appDisplayName
                                DisplayVersion =    $appDisplayVersion
                                UninstallString =   $regKeyApp.UninstallString
                                InstallSource =     $regKeyApp.InstallSource
                                InstallLocation =   $regKeyApp.InstallLocation
                                InstallDate =       $regKeyApp.InstallDate
                                Publisher =         $appPublisher
                                x64RegistryKey =    $appIn64Bit
                            }
                        }
                    }
                }
            }
        }
    }
    Return $installedApplication
}
Developer
Nov 17, 2014 at 9:56 PM
Thanks for the suggestion. The ability to detect if it is a 64-bit/32-bit application has been added to the latest 3.5 beta under the Sources tab.