Jump to content


firstcom

Java 8 Install

Recommended Posts

I'm using this "AS" a removal:

 

filename removal.cmd:

 

 

@start /wait /min %WINDIR%\System32\WindowsPowerShell\v1.0\Powershell.exe -noprofile -executionpolicy bypass -file %~dp0uninstall.ps1

 

filename uninstall.ps1

 

 

$javaVer = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |

Get-ItemProperty |
Where-Object {$_.DisplayName -match "java" } |
Select-Object -Property DisplayName, UninstallString
$MSISwitch = "/qn"
ForEach ($ver in $javaVer) {
If ($ver.UninstallString) {
$UninstGUID = ($ver.UninstallString -replace ".*{", "") -replace "}.*", ""
Start-Process -filepath "C:\Windows\system32\msiexec.exe" -argumentlist "/x{$UninstGUID}", $MSISwitch -passthru -wait
Write-Host Start-Process -filepath "C:\Windows\system32\msiexec.exe" -argumentlist "/x{$UninstGUID}", $MSISwitch -passthru -wait
}
}
Write-Host Done!

 

Like I said - Any installed Java will be removed. Use this on package or as an application removal script. Let me know if it works for you as it works for me! :)

Share this post


Link to post
Share on other sites

Be careful with that one - looks like it'll get Java-related stuff, as well.

 

E.g. "Visual Studio Extensions for Windows Library for JavaScript" gets caught by that.

 

Also won't get 32-bit installs on a 64-bit OS, since those live in hklm\wow6432node\microsoft\...

Share this post


Link to post
Share on other sites

How do you handle Java deployments/upgrades?

 

Be careful with that one - looks like it'll get Java-related stuff, as well.

 

E.g. "Visual Studio Extensions for Windows Library for JavaScript" gets caught by that.

 

Also won't get 32-bit installs on a 64-bit OS, since those live in hklm\wow6432node\microsoft\...

Share this post


Link to post
Share on other sites

How do you handle Java deployments/upgrades?

 

I also agree that uninstalling anything with "Java%" in its name is dangerous.

 

I prefer instead to run a query that brings back the Java products installed as well as the uninstall string for them. I then create a script that contains all these uninstall strings. A tad bit extra work but safer than removing all Java items on your machine.

Share this post


Link to post
Share on other sites

Yes, this script was made only for x64, but you can use for x86 as well... Just change the location where the uninstall strings are for x86.

 

Regarding other products that might used similar name (like "java") you can always add a second name that probably won't be found in other products. To test the script without executing the removal, just output the installations:

 

 

$javaVer = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |

Get-ItemProperty |
Where-Object {$_.DisplayName -match "java JRE" } |
Select-Object -Property DisplayName, UninstallString
$MSISwitch = "/qn"
ForEach ($ver in $javaVer) {
If ($ver.UninstallString) {
write-host $ver $javaVer
}
}

Share this post


Link to post
Share on other sites

Seems like you are hard to please.

 

Well you can give this a try. This is my script for the 32Bit Runtime. It uninstalls every 32Bit Version of JRE 7 & 8 (not 6 for a specific reason in our case).

It also creates a unique named hardlink for the Insallation directory under program files (request by our developers). It installs our internal certificates (Active Directory, etc), cleans up the user java cache directories (some applications will act up otherwise) and finally sets some global deployment properties for all users.

 

It also skips the whole Installation i any Java process is open (we have some critical applications which might suffer a data loss otherwise).

$VersionString = "jre1.8.0_65"

$ExitCode = 0
$myPath = Split-Path $script:MyInvocation.MyCommand.Path
Set-Location $myPath

$Process = (Get-Process 'java','javaw','javaws','javacpl' -ErrorAction SilentlyContinue -FileVersionInfo)
if ($Process){
	$ExitCode = 222
}
else {
    gwmi -Namespace root\cimv2\SMS -Class SMS_installedSoftware -Filter "ProductName Like '%Java 7 Update%' And Not ProductName Like '%Kit%' And Not ProductName Like '%64-bit%' " -Property SoftwareCode,ProductName | ForEach-Object { 
        $myArgs = "/X" + $_.SoftwareCode + " /norestart /q"
        $ExitCode = (Start-Process -FilePath "msiexec.exe" -ArgumentList $myArgs -ErrorAction SilentlyContinue -NoNewWindow -Wait -PassThru).ExitCode
    }

    gwmi -Namespace root\cimv2\SMS -Class SMS_installedSoftware -Filter "ProductName Like '%Java 8 Update%' And Not ProductName Like '%Kit%' And Not ProductName Like '%64-bit%' " -Property SoftwareCode,ProductName | ForEach-Object { 
        $myArgs = "/X" + $_.SoftwareCode + " /norestart /q"
        $ExitCode = (Start-Process -FilePath "msiexec.exe" -ArgumentList $myArgs -ErrorAction SilentlyContinue -NoNewWindow -Wait -PassThru).ExitCode
    }
    if(Test-Path 'C:\Program Files (x86)'){
        c:\windows\system32\cmd.exe /C rd 'C:\Program Files (x86)\Java\jre8' /Q
    }
    else {
        c:\windows\system32\cmd.exe /C rd 'C:\Program Files\Java\jre8' /Q
    }
    Start-Sleep 30
    $myArgs = "/i """ + $myPath + "\$VersionString.msi"" AUTOUPDATECHECK=0 JAVAUPDATE=0 JU=0 SYSTRAY=1 /norestart /q"
    $ExitCode = (Start-Process -FilePath "msiexec.exe" -ArgumentList $myArgs -ErrorAction SilentlyContinue -NoNewWindow -Wait -PassThru).ExitCode
	$Users = Get-ChildItem -Path "c:\Users"

 	$str1 = "-importcert -trustcacerts -keystore "
    $str3 = "\Java\jre8\lib\security\cacerts"" -file cert1.cer -alias cert1 -storepass changeit -noprompt"
    $str4 = "\Java\jre8\lib\security\cacerts"" -file cert2.cer -alias cert2 -storepass changeit -noprompt"
    $str5 = "\Java\jre8\lib\security\cacerts"" -file cert3.cer -alias cert3 -storepass changeit -noprompt"

    If ( Test-Path 'C:\Program Files (x86)'){
        $str2 = "C:\Program Files (x86)"
        cmd.exe /C "mklink /J ""C:\Program Files (x86)\Java\jre8"" ""C:\Program Files (x86)\Java\$VersionString"""
    }
    else {
        $str2 = "C:\Program Files"
        cmd.exe /C "mklink /J ""C:\Program Files\Java\jre8"" ""C:\Program Files\Java\$VersionString"""
    }
    $argString = $str1 + """" + $str2 + $str3
    $argString1 = $str1 + """" + $str2 + $str4
    $argString2 = $str1 + """" + $str2 + $str5
    
    $comString = $str2 + "\Java\jre8\bin\keytool.exe"
    if(Test-Path "$comString"){
        Start-Process -FilePath "$comString" -ArgumentList $argString -Wait -Passthru -NoNewWindow
 	    Start-Process -FilePath "$comString" -ArgumentList $argString1 -Wait -Passthru -NoNewWindow
 	    Start-Process -FilePath "$comString" -ArgumentList $argString2 -Wait -Passthru -NoNewWindow
    }

	foreach ($User in $Users){
		$myPath = Join-Path -Path "C:\Users" -ChildPath $User
		$Path1 = Join-Path -Path $myPath -ChildPath "AppData\LocalLow\Sun\Java\Deployment\cache"
		If ( Test-Path $Path1 ) {
			Remove-Item -Path $Path1 -Recurse -Force -ErrorAction SilentlyContinue
		}
	}
    Remove-Item -Force -Path "$env:ALLUSERSPROFILE\microsoft\windows\start menu\programs\java" -recurse -ErrorAction SilentlyContinue
    New-Item -force -Path "$env:windir\Sun\Java\Deployment\deployment.properties" -ItemType file -ErrorAction SilentlyContinue
    New-Item -force -Path "$env:windir\Sun\Java\Deployment\deployment.config" -ItemType file -ErrorAction SilentlyContinue
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.config" -value "deployment.system.config.mandatory=true" -ErrorAction SilentlyContinue
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.config" -value "deployment.system.config=file:///$env:SystemDrive/Windows/Sun/Java/Deployment/deployment.properties" -ErrorAction SilentlyContinue
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.properties" -value "deployment.expiration.check.enabled=false" -ErrorAction SilentlyContinue 
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.properties" -value "deployment.security.mixcode=HIDE_RUN" -ErrorAction SilentlyContinue 
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.properties" -value "deployment.security.level=HIGH" -ErrorAction SilentlyContinue
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.properties" -value "deployment.security.level.unlocked" -ErrorAction SilentlyContinue
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.properties" -value "deployment.insecure.jres=NEVER" -ErrorAction SilentlyContinue
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.properties" -value "deployment.javaws.shortcut=NEVER" -ErrorAction SilentlyContinue  
}
[Environment]::Exit($ExitCode)


Share this post


Link to post
Share on other sites

With the answers so far I've read various solutions but nothing that stands out to me as a consistent and concrete deployment method. I'd love to hear details from others on how they deploy Java.

 

Firstcom,

 

My honest answer... SCCM is not a standard product (like Exchange, or SQL or as HyperV). It's a product that helps you to automate your IT processes and deliver dynamic solutions based on your needs. This also means that there aren't perfect nor ideal solutions for each thing that we configured in the SCCM. My way can be different from others, but it serves my propose, but might not work for you or others. That's the thing about this product - everything can be wrong and right - because it's about outcome that you want to achieve. Example: you might use one single WIM to deliver your images or you might use 10 based on vary different aspects. It all depends! I hope you can find more solutions with for your Java or you can simply use applications and supersede older versions (if you have a MSI).

Share this post


Link to post
Share on other sites

Thank you! This script/method looks pretty solid. I'll give this a shot. Do you run into errors during Java installation? That's the issue I've been having -- occasional errors/failures during installs.

 

 

 

Seems like you are hard to please.

 

Well you can give this a try. This is my script for the 32Bit Runtime. It uninstalls every 32Bit Version of JRE 7 & 8 (not 6 for a specific reason in our case).

It also creates a unique named hardlink for the Insallation directory under program files (request by our developers). It installs our internal certificates (Active Directory, etc), cleans up the user java cache directories (some applications will act up otherwise) and finally sets some global deployment properties for all users.

 

It also skips the whole Installation i any Java process is open (we have some critical applications which might suffer a data loss otherwise).

$VersionString = "jre1.8.0_65"

$ExitCode = 0
$myPath = Split-Path $script:MyInvocation.MyCommand.Path
Set-Location $myPath

$Process = (Get-Process 'java','javaw','javaws','javacpl' -ErrorAction SilentlyContinue -FileVersionInfo)
if ($Process){
	$ExitCode = 222
}
else {
    gwmi -Namespace root\cimv2\SMS -Class SMS_installedSoftware -Filter "ProductName Like '%Java 7 Update%' And Not ProductName Like '%Kit%' And Not ProductName Like '%64-bit%' " -Property SoftwareCode,ProductName | ForEach-Object { 
        $myArgs = "/X" + $_.SoftwareCode + " /norestart /q"
        $ExitCode = (Start-Process -FilePath "msiexec.exe" -ArgumentList $myArgs -ErrorAction SilentlyContinue -NoNewWindow -Wait -PassThru).ExitCode
    }

    gwmi -Namespace root\cimv2\SMS -Class SMS_installedSoftware -Filter "ProductName Like '%Java 8 Update%' And Not ProductName Like '%Kit%' And Not ProductName Like '%64-bit%' " -Property SoftwareCode,ProductName | ForEach-Object { 
        $myArgs = "/X" + $_.SoftwareCode + " /norestart /q"
        $ExitCode = (Start-Process -FilePath "msiexec.exe" -ArgumentList $myArgs -ErrorAction SilentlyContinue -NoNewWindow -Wait -PassThru).ExitCode
    }
    if(Test-Path 'C:\Program Files (x86)'){
        c:\windows\system32\cmd.exe /C rd 'C:\Program Files (x86)\Java\jre8' /Q
    }
    else {
        c:\windows\system32\cmd.exe /C rd 'C:\Program Files\Java\jre8' /Q
    }
    Start-Sleep 30
    $myArgs = "/i """ + $myPath + "\$VersionString.msi"" AUTOUPDATECHECK=0 JAVAUPDATE=0 JU=0 SYSTRAY=1 /norestart /q"
    $ExitCode = (Start-Process -FilePath "msiexec.exe" -ArgumentList $myArgs -ErrorAction SilentlyContinue -NoNewWindow -Wait -PassThru).ExitCode
	$Users = Get-ChildItem -Path "c:\Users"

 	$str1 = "-importcert -trustcacerts -keystore "
    $str3 = "\Java\jre8\lib\security\cacerts"" -file cert1.cer -alias cert1 -storepass changeit -noprompt"
    $str4 = "\Java\jre8\lib\security\cacerts"" -file cert2.cer -alias cert2 -storepass changeit -noprompt"
    $str5 = "\Java\jre8\lib\security\cacerts"" -file cert3.cer -alias cert3 -storepass changeit -noprompt"

    If ( Test-Path 'C:\Program Files (x86)'){
        $str2 = "C:\Program Files (x86)"
        cmd.exe /C "mklink /J ""C:\Program Files (x86)\Java\jre8"" ""C:\Program Files (x86)\Java\$VersionString"""
    }
    else {
        $str2 = "C:\Program Files"
        cmd.exe /C "mklink /J ""C:\Program Files\Java\jre8"" ""C:\Program Files\Java\$VersionString"""
    }
    $argString = $str1 + """" + $str2 + $str3
    $argString1 = $str1 + """" + $str2 + $str4
    $argString2 = $str1 + """" + $str2 + $str5
    
    $comString = $str2 + "\Java\jre8\bin\keytool.exe"
    if(Test-Path "$comString"){
        Start-Process -FilePath "$comString" -ArgumentList $argString -Wait -Passthru -NoNewWindow
 	    Start-Process -FilePath "$comString" -ArgumentList $argString1 -Wait -Passthru -NoNewWindow
 	    Start-Process -FilePath "$comString" -ArgumentList $argString2 -Wait -Passthru -NoNewWindow
    }

	foreach ($User in $Users){
		$myPath = Join-Path -Path "C:\Users" -ChildPath $User
		$Path1 = Join-Path -Path $myPath -ChildPath "AppData\LocalLow\Sun\Java\Deployment\cache"
		If ( Test-Path $Path1 ) {
			Remove-Item -Path $Path1 -Recurse -Force -ErrorAction SilentlyContinue
		}
	}
    Remove-Item -Force -Path "$env:ALLUSERSPROFILE\microsoft\windows\start menu\programs\java" -recurse -ErrorAction SilentlyContinue
    New-Item -force -Path "$env:windir\Sun\Java\Deployment\deployment.properties" -ItemType file -ErrorAction SilentlyContinue
    New-Item -force -Path "$env:windir\Sun\Java\Deployment\deployment.config" -ItemType file -ErrorAction SilentlyContinue
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.config" -value "deployment.system.config.mandatory=true" -ErrorAction SilentlyContinue
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.config" -value "deployment.system.config=file:///$env:SystemDrive/Windows/Sun/Java/Deployment/deployment.properties" -ErrorAction SilentlyContinue
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.properties" -value "deployment.expiration.check.enabled=false" -ErrorAction SilentlyContinue 
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.properties" -value "deployment.security.mixcode=HIDE_RUN" -ErrorAction SilentlyContinue 
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.properties" -value "deployment.security.level=HIGH" -ErrorAction SilentlyContinue
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.properties" -value "deployment.security.level.unlocked" -ErrorAction SilentlyContinue
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.properties" -value "deployment.insecure.jres=NEVER" -ErrorAction SilentlyContinue
    Add-Content -path "$env:windir\Sun\Java\Deployment\deployment.properties" -value "deployment.javaws.shortcut=NEVER" -ErrorAction SilentlyContinue  
}
[Environment]::Exit($ExitCode)


Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.