Removing old JAVA installs

Scenario

First off, Java.com has a Java applet to do this very thing.
http://java.com/en/download/uninstallapplet.jsp

However, if you need to run this on many computers using a login script, or patch management system, here is my alternative.
It may not be complete, but it removes several versions of java using the command line uninstall method and a little brute force execution.

Prerequisites

Tested on Windows XP & 2008 R2.
Command line should be compatible with Windows 2000 or newer.

Code

BATCH Command file to remove old versions of Java.

@echo off
set newver=\\someserver\apps\Java\jre-6u21-windows-i586-s.exe

REM Install current version silently.
%newver% /passive



IF NOT EXIST "%ProgramFiles%\Java\jre7\README.TXT" (
 echo Java 7 not Found, set the newver location to automate install.
 REM you can add more logic here like:
 goto :end
) ELSE (
 echo Java 7 Found
 echo+
)



set index=0
REM Remove old Java 6 lower.  %index% represents a single character 0-9, you can add any 
REM appropriate Java GUID here replacing one digit of the minor version number.
:proc1
if %index% EQU 10 goto :endproc1
  echo %index% Uninstalling versions 0%index% 1%index% 2%index% 3%index% if present
  REM Java 6
  MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F8321600%index%FF} /q
  MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F8321601%index%FF} /q
  MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F8321602%index%FF} /q
  MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F8321603%index%FF} /q

  REM Java 1.4 - 1.6
  MsiExec.exe /X{7148F0A8-6813-11D6-A77B-00B0D01420%index%0} /q
  MsiExec.exe /X{7148F0A8-6813-11D6-A77B-00B0D01421%index%0} /q
  MsiExec.exe /X{3248F0A8-6813-11D6-A77B-00B0D01500%index%0} /q
  MsiExec.exe /X{3248F0A8-6813-11D6-A77B-00B0D01501%index%0} /q
  MsiExec.exe /X{3248F0A8-6813-11D6-A77B-00B0D01600%index%0} /q
  MsiExec.exe /X{3248F0A8-6813-11D6-A77B-00B0D01601%index%0} /q


  set /a index+=1
  goto :proc1

:endproc1


:end