windows – 要卸载所有Sun Java版本的批处理文件?

前端之家收集整理的这篇文章主要介绍了windows – 要卸载所有Sun Java版本的批处理文件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在建立一个系统来保持 Java在我们办公室的最新状态.每个人都拥有所有不同版本的Java,其中许多都是旧的和不安全的,有些可以追溯到1.4.我有一个System Center Essentials服务器,可以推出并静默运行.msi文件,我已经测试过它可以安装最新的Java.但安装程序不会删除旧版本(例如1.4),因此我需要卸载它们.每个人都在运行Windows XP.

巧合的是,Sun刚刚被Oracle收购,而Oracle现在已经将Java中所有“Sun”实例改为“Oracle”.因此,我可以不用担心卸载最新的Java,因为我可以只搜索并卸载所有Sun Java程序.

我在a forum 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来阻止它.

通过脚本阅读,我并不了解所有内容,但我不知道为什么它会尝试将各个注册表项作为程序运行.批处理脚本有什么问题?我该如何修复它,以便我可以继续以某种方式将其转换为MSI并将其部署到每个人来清理这个办公室?

或者,你能建议一个更好的解决方案或现有的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",True
' Uninstall Java 5.0.2
WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150020} /q",True
' Uninstall Java 5.0.4
WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150040} /q",True
' Uninstall Java 5.0.5
WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150050} /q",True
' Uninstall Java 5.0.6
WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150060} /q",True
' Uninstall Java 5.0.7
WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150070} /q",True
' Uninstall Java 5.0.10
WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150100} /q",True
' Uninstall Java 5.0.11
WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150110} /q",True
' Uninstall Java 5.0.12
'WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0150120} /q",True
' Uninstall Java 6.0.0
WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0160000} /q",True
' Uninstall Java 6.0.1
WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0160010} /q",True
' Uninstall Java 6.0.2
WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0160020} /q",True
' Uninstall Java 6.0.5
WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0160050} /q",True
' Uninstall Java 6.0.30 (020608)
WshShell.Run "msiexec /x {3248F0A8-6813-11D6-A77B-00B0D0160030} /q",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","REG_SZ"

End Sub
原文链接:https://www.f2er.com/windows/370015.html

猜你在找的Windows相关文章