r/sysadmin • u/vocatus InfoSec • Jul 12 '13
Java Runtime Nuker - purge ALL versions of the Java Runtime
x-post from /r/usefulscripts
I thought you guys and gals might find this handy.
Bottom line: Forget other methods of removing Java you've used - this is ultimate Java Removal Script. If a JRE manages to squeak through, tell me and I'll update the script to catch it.
Because of inconsistencies in Sun/Oracle's installation methods and naming conventions, there's no "one way" to purge every outdated Java Runtime from a machine, so I spent about ~17 hours collecting various methods of removing Java and integrated them into a single script. This should give you a "clean slate" to work with for laying down new versions of Java.
Tested against these JRE versions specifically, but should work to remove ANY version of JRE:
- JRE 1.4.2 Update 19
- JRE 5.0 Update 4
- JRE 5.0 Update 5
- JRE 5.0 Update 16 (64-bit)
- JRE 6.0 Update 25
- JRE 6.0 Update 25 (64-bit)
- JRE 6.0 Update 27
- JRE 6.0 Update 45
- JRE 7.0 Update 4
- JRE 7.0 Update 16 (64-bit)
- JRE 7.0 Update 21 (64-bit)
- JRE 7.0 Update 25
- JRE 7.0 Update 25 (64-bit)
Additionally, the box I tested on had these JDK versions installed, and they were successfully left untouched:
- JDK 6 Update 45
- JDK 7 Update 25
- JDK 7 Update 25 (64-bit)
Download
v1.5.0 (2013-07-23)
v1.4.1 (2013-07-18)
v1.4 (2013-07-16)
v1.3 (2013-07-15)
v1.2 (2013-07-13)
v1.1 (2013-07-12)
Notes:
- Removes all versions of the Java Runtime Environment (series 3 through 7), both x86 and x64.
- Will catch future updates to JRE 5, 6 and 7
- Checks WMI before running, and repairs it if broken
- Searches for residual registry keys, backs them up, then deletes them*
- Searches for residual files and directories and deletes them
- Removes the Java Quickstarter and Java Updater services
- Leaves all Java Development Kit installations intact
- Writes a logfile to C:\Logs\<hostname>_java_runtime_nuker.log (configurable)
- New: Option to reinstall newest Java after finishing cleanup. Set the REINSTALL_JAVA variable to 'yes' if you want the script to do this. Off by default. (thanks to /u/sdjason)
- New: Option to check for running Java processes first, and abort the script if found. Off by default. (thanks to /u/sdjason)
If you have additional methods that work for you, please post them on the original thread here. If they catch something my script misses, I will integrate them into it. Critique and advice welcome.
*Currently the registry cleanup section is skipped on Windows XP. This is because of differences in the "reg.exe" binary in Windows XP. If anyone can look at how to search the Windows XP registry for leftover keys, I can integrate it into the script, but right now just know that section is skipped.
2
u/Hellman109 Windows Sysadmin Jul 14 '13
THANK YOU!
Ill test it next week, I have some scripts I made to clear out various parts but never everything/
One question - some upgrades leave remenants of the previous uninstallers around - do you remove them?
2
u/sdjason Jul 14 '13
This Is Awesome. I took a stab at this a few months back, but your is way more robust than the one i had come up with.
One suggestion I have (i'm going to add it in myself at work next week most likely to use it for my purposes) is to add in an optional java install step right at the end)
I can set a variable JAVA_Install=1 at the beginning of the script as well as something like JAVA_INSTALL_EXEName=javasetupname.exe and if both of those are set, the last step of the script will install java (assuming the exe sits in same dir as the script, use %~dp0 .
This would be useful for software deployment tools (like pdqdeploy, sccm, altiris, ect) They "can" chain things together, or make another script to call both things in sequence, but having the option right in the script would also be nice. It can then be use to uninstall OR uninstall/reinstall the company managed/approved version, in nearly all scenarios. Meaning I can tell the desktop support guys "anytime something is wrong with Java, go run this script and it should fix it"
Just a suggestion, but freaking awesome script!
1
u/MrYiff Master of the Blinking Lights Jul 18 '13
Very cool, just testing it on my PC and getting some errors when it is trying to run the taskkill bits:
1
u/bluefirecorp Jul 13 '13
OHH! That's neat. I might have to include that in my Java installer on my PDQ Deploy package.
0
u/[deleted] Jul 13 '13
[deleted] — view deleted comment