I'm setting up a system to keep Java in our office up to date. Everyone has all different versions of Java, many of them old and insecure, and some dating back as far as 1.4. I have a System Center Essentials server which can push out and silently run a .msi file, and I've already tested that it can install the latest Java. But old versions (such as 1.4) aren't removed by the installer, so I need to uninstall them. Everyone is running Windows XP.
The neat coincidence is that Sun just got bought by Oracle and Oracle has now changed all the instances of "Sun" to "Oracle" in Java. So, I can conveniently not have to worry about uninstalling the latest Java, because I can just do a search and uninstall all Sun Java programs.
I found the following batch script on a forum post which looked promising:
@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
However, when I run the script, I get the following output:
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.
And then it appears to hang and I ctrl-c to stop it.
Reading through the script, I don't understand everything, but I don't know why it is trying to run pieces of registry keys as programs. What is wrong with the batch script? How can I fix it, so that I can move on to somehow turning it into a MSI and deploying it to everyone to clean up this office?
Or alternatively, can you suggest a better solution or existing MSI file to do what I need? I just want to make sure to get all the old versions of Java off of everyone's computers, since I've heard of exploits that cause web pages to load using old versions of Java and I want to avoid those.