Tuesday, February 03, 2015

How to uninstall any version of Java

I wanted to uninstall Java from all the machines and install the latest one. There were sometimes multiple versions of Java which had to be removed. Some machines had both 32 bit and 64 bit Java versions. Here is the easiest batch script to uninstall any version of Java on the machine.
There were scripts available but they did not delete 64 bit versions of Java and some very old versions of Java. Hence I modified those scripts to meet my need.

set mycmd=reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s /f *java* for /f " usebackq delims={} tokens=2" %%i IN (`%mycmd%`) do ( msiexec /uninstall {%%i} /passive )
set mycmd=reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /s /f *java* for /f " usebackq delims={} tokens=2" %%i IN (`%mycmd%`) do ( msiexec /uninstall {%%i} /passive )

4 comments:

Cristhian Prieto said...

Hi Piyush,

I'm trying to test this batch file, which I also found over at http://en.wiki.schrotti12.eu/index.php/Remove_all_old_Java_versions but whenever I try to run it (saved to a .bat) I keep getting an Error: Too many command-line parameters. Any ideas?

Piyush Nasa said...

Did you try running it with Admin Privileges?
Make sure the quotes are correct as well. In `%mycmd%` it is actually ` and not '

Bug Eyes said...

I'm too saved the above script to a bat file, run it with Admin Privileges but received an error message 'The system cannot find the path specified.'

Piyush Nasa said...

Can you check if there are no undesired enter added in the lines. Also you need to check if the Add/Remove program has java in the name. Also check my previous comment in which you have to take care of quotes.
Hope it helps.