Jump to content

Made a Script to Uninstall All Older Versions of Java and Install Latest Java 8_xx


Recommended Posts

Posted

Due to the recent changes to Java deployment, to be exact

 

"Staring with Java 8 Update 20, Oracle’s Java installers will no longer automatically remove previous versions of Java 8 Update X during a silent installation."

I've been looking into all possibilities to deploy this via .bat file upon start up with Group Policy. I don't have SCCM and I've preferred to stick with GP. As of now if the run time for this script is to long you can always take out chunks like "wmic product where "name like 'JavaFX%%'" call uninstall /nointeractive" if you know none of your computers have Java FX. But it will uninstall all older versions from Java 6 to 8 including FX and J2SE. It's also easy to update for when the next update of Java comes out, all you have to do is change the path under "::Check Version here" and "::Install Latest Version here". It's not 100% fool proof though, if older versions of Java are installed along side the current version it will not uninstall older version. Anyways, Enjoy

 

 

 

@ECHO OFFcls
TITLE Updating Java


::Check Current Version here
IF EXIST "C:\Program Files\Java\jre1.8.0_31" goto END


::Uninstall Older Versions here if Current Version is not installed
wmic product where "name like 'Java 7%%'" call uninstall /nointeractive
wmic product where "name like 'Java 8%%'" 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 'Java(tm) 8%%'" call uninstall /nointeractive
wmic product where "name like 'J2SE Runtime Environment%%'" call uninstall /nointeractive


::Install Current Version here
msiexec.exe /i [b]FileLocation[/b]\jre1.8.0_31.msi
goto END


:END
exit

Posted
Using "wmic product" is a bad idea. Check your event logs and you'll see why. :)

 

 

I've checked my event logs and found nothing that stuck out. Any reason why I shouldn't use wmic_product? I've tested on about 30+ XP and 7 machines both 64 and 32 and various older versions of 6, 7 and 8 and all seem to be perfectly fine. I will admit though, it is a fairly slow script to run.

Posted
The following article explains why.

 

https://sdmsoftware.com/group-policy-blog/wmi/why-win32_product-is-bad-news/

 

Currently on my phone, otherwise I would post a few more links.

 

 

 

I now see the issue and that explains the delay. This It's triggering previously installed .msi in order to create a query but it's not really doing anything with them beside triggering "repair"

 

Any suggestions on a work around or other method?

Posted

Fortunately, I'm using SCCM, so I can just set the "supersedence" flag in the Application properties.

You select the application that you want replace, and when you deploy the new one, the old one is automatically uninstalled

 

Just done this to replace Update 25 with Update 31

Posted (edited)
Any suggestions on a work around or other method?

Since you don't have SCCM there are a couple of things you could do.

 

  1. Use the Remove-MSIApplications and Execute-MSI functions included with the PowerShell App Deployment Toolkit to create a script that does the exact same thing as your batch file.
     
    I have uploaded an example for Java here if you want to give it a try? :)
     
     
  2. Write your own batch file / script that queries the registry for the software you want to uninstall. Specifically these keys...
     
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall


Edited by Arthur

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...