Ich muss zugeben, dass ich in der kein großer Freund von Java bin. Trotzdem ist Java auf der Mehrzahl aller PCs installiert und sollte aus Sicherheitsgründen zwingend in der neuesten Version betrieben werden. Ein einfaches Update auf eine neuere Version reicht jedoch nicht aus. Ältere Versionen sollten im Vorfeld rückstandslos vom System entfernt werden.
Für die rückstandlose Deinstallation von Java habe ich ein Powershell-Skript geschrieben, das alle bestehenden Java-Installationen ermittelt und im Anschluss deinstalliert. Das Skript überprüft dabei die momentan installierten Versionen über die Registry und führt die jeweils hinterlegten UninstallStrings in abgeänderter Form aus. Im Anschluss werden die Registry und das Dateisystem durch das gezielte Löschen von Überresten befreit. Dabei spielt es keine Rolle, um welche Java-Version es sich handelt. Folgende Verzeichnisse werden gelöscht:
- %ProgramFiles(x86)%\Java
- %ProgramFiles%\Java\
- %windir%\sun\java
- %userprofile%AppData\LocalLow\Sun\Java
Optionale Neuinstallation: Liegt eine aktuelle Java-Version als MSI-Datei im gleichen Ordner wie das Powershell-Skript, dann wird diese im Anschluss automatisch installiert. Dabei werden folgende Konfigurationsparameter mitgegeben.
deployment.javaws.autodownload=NEVER deployment.javaws.autodownload.locked deployment.expiration.check.enabled=FALSE deployment.security.level=MEDIUM deployment.security.level.locked
Durch die Konfigurationsparameter werden die Java-Sicherheitsebene auf Medium festgesetzt und die integrierte Updatefunktion deaktiviert. Letzteres macht insbesondere im Enterprise-Umfeld Sinn. Die jeweiligen Parameter beschreibt Oracle unter diesem Link recht umfangreich.
Anleitung am Beispiel Java SE Runtime Environment 7 Update 51
Schritt 1: Download Offline-Installer Java SE Runtime Environment 7 Update 51
Am Beispiel Java SE Runtime Environment 7 Update 51 muss im ersten Schritt der Offline-Installer heruntergeladen werden. Die Version nach Wahl kann über diesen Link heruntergeladen werden:
Schritt 2: Java SE Runtime Environment Update 51 Offline-Installer entpacken
Im Anschluss muss die MSI-Datei aus der heruntergeladen EXE-Datei exportiert werden. Dazu muss das Setup lediglich aufgerufen werden. Die Setup-Routine legt dann die MSI-Datei unter folgendem Pfad temporär ab.
C:\Users\%username%\AppData\LocalLow\Sun\Java\
Der Verzeichnisinhalt muss, sofern eine Java-Neuinstallation und -Konfiguration gewünscht ist, in das Powershell-Skript-Verzeichnis kopiert werden. Im Anschluss kann das Powershell-Skript einfach ausgeführt werden.
Schritt 3: Verteilung mit dem Configuration Manager (optional)
Das Skript kann natürlich auch als Package über den Configuration Manager ausgeführt werden. Am einfachsten ist es wohl, das Script mit folgender Befehlszeile auszuführen.
powershell.exe -ExecutionPolicy Bypass -file "clientmgmtde_reinstallljava.ps1"
uninstalljava.ps1 (Clientmgmt.de-Reinstall-Java-Script)
##################################################################### ### Uninstall all previous Java-Installations with Powershell ### powered by Andre Picker - www.clientmgmt.de ### http://twitter.com/clientmgmt ##################################################################### ##################################################################### ### Check which java versions are installed ##################################################################### $javaVer = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall -ErrorAction 0 | Get-ItemProperty | Where-Object {$_.DisplayName -match "Java" -or $_.DisplayName -match "J2SE" } | Select-Object -Property DisplayName, UninstallString ##################################################################### ### Silent uninstall of all previous Java-Installations ### Kill iexplore, firefox, java, jp2launcher, jawaw, jqs, jusched ##################################################################### kill -processname iexplore, firefox, java, jp2launcher, jawaw, jqs, jusched -Force -ErrorAction SilentlyContinue ForEach ($ver in $javaVer) { If ($ver.UninstallString) { $uninst = $ver.UninstallString $startmsiguid = $uninst.IndexOf("{") $endmsiguid = $uninst.IndexOf("}") +1 - $startmsiguid $msiguid = $uninst.Substring($startmsiguid,$endmsiguid) cmd /c start /wait msiexec /x $msiguid /qn REBOOT=ReallySuppress } } ##################################################################### ### Delete not required Java-Folders ### %ProgramFiles(x86)%\Java, %ProgramFiles%\Java\, %windir%\sun\java ##################################################################### Remove-Item -Recurse -Force -ErrorAction 0 @( ${env:ProgramFiles(x86)} + '\java' $env:ProgramFiles + '\java' $env:windir + '\sun\java' ) ##################################################################### ### Delete not required Registry-Entries ### HKLM:\SOFTWARE\JavaSoft, HKLM:\SOFTWARE\Wow6432Node\JavaSoft ##################################################################### Remove-Item -Recurse -Force -ErrorAction 0 @( 'HKLM:\SOFTWARE\Wow6432Node\JavaSoft' 'HKLM:\SOFTWARE\JavaSoft' ) ##################################################################### ### Delete UserProfile Java-Cache ### HKLM:\SOFTWARE\JavaSoft, HKLM:\SOFTWARE\Wow6432Node\JavaSoft ##################################################################### $colProfiles = Get-ChildItem "C:\Users\" -Name -ErrorAction SilentlyContinue $colProfiles | ForEach-Object { Get-ChildItem C:\Users\$_\AppData\LocalLow\Sun\* -Recurse -force -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue } ##################################################################### ### Checking for successful uninstall and Modify exit code ##################################################################### $check = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall -ErrorAction 0 | Get-ItemProperty | Where-Object {$_.DisplayName -match "Java" -or $_.DisplayName -match "J2SE" } if ($check -eq $null) { $exitcode = '0' } else { $exitcode = '1' } ##################################################################### ### Install Java SE Runtime Environment if .msi-File is available ### Select MSI-File from Scriptfolder ### Url: http://www.oracle.com/technetwork/java/javase/downloads/ ##################################################################### $filename = Get-ChildItem -Name -Filter *.msi if ($filename -eq $null) { exit $exitcode } else { cmd /c start /wait msiexec /i $filename /qn REBOOT=ReallySuppress } ##################################################################### ### Remove Startmenu-Shortcuts ##################################################################### Remove-Item -Recurse -Force -ErrorAction 0 @( $env:ALLUSERSPROFILE + '\Microsoft\Windows\Start Menu\Programs\Java' ) ##################################################################### ### Configure Java SE Runtime Environment ### http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/jcp/properties.html ### deployment.javaws.autodownload=NEVER ### deployment.javaws.autodownload.locked ### deployment.expiration.check.enabled=FALSE ### deployment.security.level=MEDIUM ### deployment.security.level.locked ##################################################################### New-Item -ItemType directory -Path $env:windir\Sun\Java\Deployment\ -Force -ErrorAction 0 Copy-Item -Path .\deployment.config -Destination $env:windir\Sun\Java\Deployment\ -Force -ErrorAction 0 Copy-Item -Path .\deployment.properties -Destination $env:windir\Sun\Java\Deployment\ -Force -ErrorAction 0 exit $exitcode