我正在build立一个系统让Java在我们的办公室保持最新。 每个人都拥有所有不同的Java版本,其中许多都是老的和不安全的,有些可以追溯到1.4。 我有一个System Center Essentials服务器,可以推出并静默运行一个.msi文件,我已经testing过它可以安装最新的Java。 但旧版本(如1.4)不会被安装程序删除,所以我需要卸载它们。 每个人都在运行Windows XP。
巧合的是,Sun刚刚被甲骨文收购,甲骨文现在已经把所有的“Sun”实例改为Java的“Oracle”。 所以,我可以方便地不用担心卸载最新的Java,因为我可以只search和卸载所有的Sun Java程序。
我在论坛post中发现了以下批处理脚本,看起来很有希望:
@echo off & cls Rem List all Installation subkeys from uninstall key. echo Searching Registry for Java Installs for /f %%I in ('reg query HKLM\SOFTWARE\microsoft\windows\currentversion\uninstall') do echo %%I | find "{" > nul && call :All-Installations %%I echo Search Complete.. goto :EOF :All-Installations Rem Filter out all but the Sun Installations for /f "tokens=2*" %%T in ('reg query %1 /v Publisher 2^> nul') do echo %%U | find "Sun" > nul && call :Sun-Installations %1 goto :EOF :Sun-Installations Rem Filter out all but the Sun-Java Installations. Note the tilda + n, which drops all the subkeys from the path for /f "tokens=2*" %%T in ('reg query %1 /v DisplayName 2^> nul') do echo . Uninstalling - %%U: | find "Java" && call :Sun-Java-Installs %~n1 goto :EOF :Sun-Java-Installs Rem Run Uninstaller for the installation MsiExec.exe /x%1 /qb echo . Uninstall Complete, Resuming Search.. goto :EOF
但是,当我运行脚本,我得到以下输出:
Searching Registry for Java Installs 'DEV_24x6' is not recognized as an internal or external command, operable program or batch file. 'SUBSYS_542214F1' is not recognized as an internal or external command, operable program or batch file.
然后它似乎挂起,我按Ctrl-C来停止它。
通过脚本阅读,我不明白一切,但我不知道为什么它试图运行registry项作为程序。 批处理脚本有什么问题? 我该如何解决这个问题,以便我可以把它变成一个MSI,并将它部署到每个人来清理这个办公室?
或者,您可以build议一个更好的解决scheme或现有的MSI文件来做我所需要的吗? 我只想确保从所有人的计算机中获得Java的所有旧版本,因为我听说过利用旧版Java加载网页的漏洞,我想避免这些漏洞。
以下是我们使用的,作为启动脚本很好:
on error resume next dim WshShell dim RegKey dim ScriptVerKey Set WshShell = CreateObject("WScript.Shell") 'checks to see if registry key exists, if it does, the cleanup runs. RegKey = "HKLM\SOFTWARE\EDU\Cleanup\" ScriptVerKey = WshShell.RegRead(RegKey & "JAVAOldVer") if ScriptVerKey <> "1" Then Cleanup() Else WScript.Quit End If Sub Cleanup() ' Uninstall Java 1.4.1.01 WshShell.Run "msiexec /x {1666FA7C-CB5F-11D6-A78C-00B0D079AF64} /q",1,True ' Uninstall Java 1.4.2.04 WshShell.Run "msiexec /x {7148F0A8-6813-11D6-A77B-00B0D0142040} /q",1,True ' Uninstall Java 5.0.2 WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150020} /q",1,True ' Uninstall Java 5.0.4 WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150040} /q",1,True ' Uninstall Java 5.0.5 WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150050} /q",1,True ' Uninstall Java 5.0.6 WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150060} /q",1,True ' Uninstall Java 5.0.7 WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150070} /q",1,True ' Uninstall Java 5.0.10 WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150100} /q",1,True ' Uninstall Java 5.0.11 WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150110} /q",1,True ' Uninstall Java 5.0.12 'WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150120} /q",1,True ' Uninstall Java 6.0.0 WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0160000} /q",1,True ' Uninstall Java 6.0.1 WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0160010} /q",1,True ' Uninstall Java 6.0.2 WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0160020} /q",1,True ' Uninstall Java 6.0.5 WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0160050} /q",1,True ' Uninstall Java 6.0.30 (020608) WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0160030} /q",1,True 'regkey below stops the script from running again WshShell.RegWrite "HKLM\Software\EDU\", "Default" WshShell.RegWrite "HKLM\Software\EDU\Cleanup\", "Default" WshShell.RegWrite "HKLM\Software\EDU\Cleanup\JAVAOldVer", 1, "REG_SZ" End Sub
这一行将卸载所有版本的JAVA:
wmic产品其中“名称像”Java %% %%“”调用卸载/ nointeractive
摘自: http : //www.java.com/en/download/faq/remove_olderversions.xml
随着时间的推移,您可能已经安装了多个Java版本来运行可用的Java内容。 过去,每个Java更新都安装在系统上的不同目录中。 但是,Java更新现在安装在一个目录中。
我应该删除旧版本的Java吗? 我们强烈build议用户从系统中删除所有旧版本的Java。 在您的系统上保留旧的和不受支持的Java版本会带来严重的安全风险。 从您的系统中删除较旧版本的Java,可确保Java应用程序在系统上运行时具有最新的安全性和性能改进。
我发现了下面的VBScript,理论上它可以正确删除以前的Java版本。 最好从下往上阅读 ,因为别人已经调整到完美:
检查这个简单但非常有用的命令:
wmic product where "name like 'Java(TM) 6%%'" call uninstall /nointeractive
从这里偷来的
这里有一些vbscript代码,你应该可以通过组策略部署而不需要msi。
最高投票的validation答案有一些问题。 根据我的testing,6.0系列CLSID不正确。
这里是我发现为每个JRE系列工作的CLSID。 将xxreplace为您想要删除的所需版本。 请使用https://serverfault.com/a/187552/172014
4.2_xx {7148F0A8-6813-11D6-A77B-00B0D0142xx0} 5.0_xx {3248F0A8-6813-11D6-A77B-00B0D0150xx0} 6.0_xx {26A24AE4-039D-4CA4-87B4-2F832160xxF0} 7.0_xx {26A24AE4-039D-4CA4-87B4-2F832170xxF0}
我build议在/ q之后添加/ norestart,以防万一1.4.2系列JRE MSI需要重启。
msiexec /x <insert_CLSID_here> /q /norestart
您仍然可以使用批处理脚本完成。 我使用下面的脚本;
@ECHO OFF REM ####################################################### REM AUTHOR: HeyVooN REM BLOG: http://blog.teksoporte.es REM DATE CREATED: 09/04/2015 REM Deploy Java to your Enterprise REM This script is optimised for 32 and 64 Bit versions of Java to be installed on either 32 or 64 bit REM operating systems. It can easily accommodate 64 bit versions of Java. REM This script removes all previous versions of Java installed prior to (re)install any version. REM ####################################################### REM ####################################################### REM SECTION 1 - CLEAN UP PC BEFORE INSTALLING JAVA (This section is not mandatory) REM ####################################################### ECHO ------------------------------------------------------- ECHO STOP PROCESSES ECHO ------------------------------------------------------- REM Assuming that processes using Java are stopped before uninstalling existing versions of Java REM Common processes using Java: firefox.exe, iexplore.exe, chrome.exe, jusched.exe, jucheck.exe, java.exe, javacpl.exe sc config "UI0Detect" start= disabled sc stop UI0Detect taskkill /F /IM jusched.exe /T taskkill /F /IM jucheck.exe /T taskkill /F /IM java.exe /T ECHO ------------------------------------------------------- ECHO UNISTALL ANY PREVIOUS VERSIONS OF JAVA 32 Bit ECHO ------------------------------------------------------- SET jver="Java 7" SET regVar32=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall SET myCMD=REG QUERY %regVar32% /s /f %jver% FOR /f " usebackq delims={} tokens=2" %%i IN (`%myCMD%`) DO ( ECHO Uninstall Key: {%%i} ECHO Condition: %uinstallState% START /WAIT MSIEXEC /x {%%i} /qn /norestart ) ECHO ------------------------------------------------------- ECHO UNISTALL ANY PREVIOUS VERSIONS OF JAVA 64 Bit ECHO ------------------------------------------------------- SET jver="Java 7" SET regVar64=HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ SET myCMD=REG QUERY %regVar64% /s /f %jver% FOR /f " usebackq delims={} tokens=2" %%i IN (`%myCMD%`) DO ( ECHO Uninstall Key: {%%i} ECHO Condition: %uinstallState% START /WAIT MSIEXEC /x {%%i} /qn /norestart ) ECHO ------------------------------------------------------- ECHO CLEANING REGISTRY ECHO ------------------------------------------------------- REM Removing known problem registry keys. I use the below line to SET the variable of which reg.exe to use depending on OS architecture. REM Additional registry removal strings can be added here. @If Defined ProgramFiles(x86) (SET "Reg32Path=%SystemRoot%\SysWOW64\reg.exe") Else (SET "Reg32Path=%SystemRoot%\System32\reg.exe") REM %Reg32Path% DELETE HKLM\SOFTWARE\JavaSoft /va /f %Reg32Path% DELETE "HKLM\SOFTWARE\JavaSoft\Auto Update" /va /f %Reg32Path% DELETE "HKLM\SOFTWARE\JavaSoft\Java Update" /va /f ECHO ------------------------------------------------------- ECHO DELETE START MENU ITEMS ECHO ------------------------------------------------------- RD /s /q "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Java" PAUSE EXIT /B 0
您可以调整/修改您想要的方式以满足您的需求。 😉
这对我有效。 它会在最新版本(在编写本文时为v8.0.66)之前卸载所有版本的Java(32位和64位)。
wmic product where "name like 'Java%%' and version < '8.0.66'" call uninstall