Jump to content

Looking for a Script or Batch file to remove previous versions of Java


Recommended Posts

Posted

Good afternoon,

 

I was wondering whether if someone can help me with a script or a batch file that will remove all previous versions of Java completely, as we have over 500 Windows 7x64 Workstations.

 

Once all previous versions of Java uninstalled, I am then going to deploy the latest version of Java using Group Policy.

 

Can someone please help.

 

Many Thanks

Posted

I probably got this from someone on here (or off the net), but this worked for me.

 

@ECHO OFF

If EXIST "C:\JavaRemove.txt" goto :END

cls

TITLE Uninstalling Java 5-8 and Java fx. . .

wmic product where "name like 'Java 7%%'" call uninstall /nointeractive
wmic product where "name like 'JavaFX%%'" call uninstall /nointeractive
wmic product where "name like 'Java(TM) 7%%'" call uninstall /nointeractive
wmic product where "name like 'Java(tm) 6%%'" call uninstall /nointeractive
wmic product where "name like 'J2SE Runtime Environment%%'" call uninstall /nointeractive
wmic product where "name = 'java 8 update 0'" call uninstall /nointeractive
wmic product where "name = 'java 8 update 05'" call uninstall /nointeractive
wmic product where "name = 'java 8 update 20'" call uninstall /nointeractive
wmic product where "name = 'java 8 update 25'" call uninstall /nointeractive
wmic product where "name = 'java 8 update 31'" call uninstall /nointeractive

echo Removed >> "C:\JavaRemove.txt"

goto END

:END

exit

 

You'll have to add subsequent 8.* versions in. Hopefully you won't have any Java 4 or earlier.

  • Thanks 1
Posted (edited)
I probably got this from someone on here (or off the net), but this worked for me.

 

@ECHO OFF

If EXIST "C:\JavaRemove.txt" goto :END

cls

TITLE Uninstalling Java 5-8 and Java fx. . .

wmic product where "name like 'Java 7%%'" call uninstall /nointeractive
wmic product where "name like 'JavaFX%%'" call uninstall /nointeractive
wmic product where "name like 'Java(TM) 7%%'" call uninstall /nointeractive
wmic product where "name like 'Java(tm) 6%%'" call uninstall /nointeractive
wmic product where "name like 'J2SE Runtime Environment%%'" call uninstall /nointeractive
wmic product where "name = 'java 8 update 0'" call uninstall /nointeractive
wmic product where "name = 'java 8 update 05'" call uninstall /nointeractive
wmic product where "name = 'java 8 update 20'" call uninstall /nointeractive
wmic product where "name = 'java 8 update 25'" call uninstall /nointeractive
wmic product where "name = 'java 8 update 31'" call uninstall /nointeractive

echo Removed >> "C:\JavaRemove.txt"

goto END

:END

exit

 

You'll have to add subsequent 8.* versions in. Hopefully you won't have any Java 4 or earlier.

 

Oooh clever, so I could do "java 8%%" in the above to remove ALL version 8 java. I had been doing it this way:

 

REM 32 bit
start /wait msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83218045F0} /qn /norestart
start /wait msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83218091F0} /qn /norestart
start /wait msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F32180101F0} /qn /norestart
start /wait msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F32180111F0} /qn /norestart
start /wait msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F32180121F0} /qn /norestart
start /wait msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F32180131F0} /qn /norestart
start /wait msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F32180144F0} /qn /norestart
REM 64 bit

start /wait msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86418045F0} /qn /norestart
start /wait msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86418091F0} /qn /norestart
start /wait msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F64180101F0} /qn /norestart
start /wait msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F64180111F0} /qn /norestart
start /wait msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F64180121F0} /qn /norestart
start /wait msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F64180131F0} /qn /norestart
start /wait msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F64180144F0} /qn /norestart

which removed 8u45/91/101/111/121/131/144 (which are the versions I have installed as I don't update as fast as they spew out new updates)

(That went in a start up script and only ran the uninstall sections if an old version was present, followed up by the installer for the new version)

Edited by Katy
This editor hates me pasting anything in :(
Posted
Oooh clever, so I could do "java 8%%" in the above to remove ALL version 8 java.

 

Good point! The OP was going for a "nuke then install" approach, so that would be a smarter option.

 

NB @Addy-Hussain usual test on an isolated machine warnings apply (for the script I posted at least - I wouldn't want to suggest that anyone else's needed testing!).

  • 4 weeks later...
Posted
I have a piece of code I wrote that does not use WMIC, as I found it is slow and you do not need to add any lines as it will handle any java 8 version as is. If anyone is interested in the AutoIT script; you will have to compile it ?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...