Home > Deployment, Scripting > Batch Script for automatically uninstalling all Java Runtime Environment (JRE) Instances on a PC

Batch Script for automatically uninstalling all Java Runtime Environment (JRE) Instances on a PC

Below, you’ll find a Little helper script that fully automatically uninstalls all Java Runtime Environment (JRE) Instances from JRE 1.4 up to JRE 1.7 from the targeted machine. This might come in handy if you want to clean up a PC from old JRE junk Prior to deploying the most current Version.

remove-jre

  • You must run the Script with Admin rights.
  • The Script works with both x86 and x64 machines.
  • It recognizes the x86 and x64 Versions of the JRE up to JRE 1.6 Update 39 and JRE 1.7 Update 13.
  • You will Need at least Windows XP. You may can modify it to work with Windows 2000 when you use reg.exe from the Resource Kit and kill.exe from Sysinternals.

uninstall-jre.bat

:: Bulk JRE Uninstaller
:: Written by:
:: Uwe Stoppel < uwe/at/stoppel.name > < https://heyfryckles.wordpress.com >

@echo off

goto start

:uninstall_helper

	set SWUUID=%1

	:: Remove Quotation Marks
	set SWUUID=###%SWUUID%###
	set SWUUID=%SWUUID:"###=%
	set SWUUID=%SWUUID:###"=%
	set SWUUID=%SWUUID:###=%

	:: Searching the 32-Bit Regkeys for our UUID
	set REGKEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%SWUUID%	
	@call reg.exe QUERY "%REGKEY%" > nul 2>&1
	if %ERRORLEVEL% == 0 (
		goto uninstall
	)
	
	:: Searching the 64-Bit Regkeys for our UUID
	set REGKEY=HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\%SWUUID%
	@call reg.exe QUERY "%REGKEY%" > nul 2>&1
	if %ERRORLEVEL% == 0 (
		goto uninstall
	)
	
	goto finish

:uninstall

	set SERVICES=HKLM\SYSTEM\CurrentControlSet\Services

	:: If the Java Quick Starter Service is present, we stop it
	@call reg.exe QUERY "%SERVICES%\JavaQuickStarterService" > nul 2>&1
	if %ERRORLEVEL% == 0 (
		@echo Stopping Service Java Quick Starter...
		@call net.exe stop JavaQuickStarterService > nul 2>&1
		@call taskkill.exe /F /IM jqs.exe
	)

	:: Killing all remaining Java processes
	@call taskkill.exe /F /IM javaw.exe > nul 2>&1
	@call taskkill.exe /F /IM javaws.exe > nul 2>&1

	:: Killing all OpenOffice processes...
	@call taskkill.exe /F /IM soffice.bin.exe > nul 2>&1
	@call taskkill.exe /F /IM soffice.exe > nul 2>&1
	@call taskkill.exe /F /IM swriter.exe > nul 2>&1
	@call taskkill.exe /F /IM scalc.exe > nul 2>&1
	@call taskkill.exe /F /IM sdraw.exe > nul 2>&1
	@call taskkill.exe /F /IM simpress.exe > nul 2>&1
	@call taskkill.exe /F /IM smath.exe > nul 2>&1
	@call taskkill.exe /F /IM sweb.exe > nul 2>&1

	for /F "tokens=2*" %%a in ('reg.exe QUERY "%REGKEY%" /v DisplayName ^|findstr DisplayName') DO SET SWNAME=%%b
	
	@echo Uninstalling %SWNAME%...
	@call MsiExec.exe /qn /norestart /x %SWUUID%

goto finish

:start

	@echo Searching for installed JRE instances...

	:: Java Runtime Environment 1.7 (x64)
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86417013FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86417012FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86417011FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86417010FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86417009FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86417008FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86417007FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86417006FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86417005FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86417004FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86417003FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86417002FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86417001FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86417000FF}"

	:: Java Runtime Environment 1.7 (x86)
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83217013FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83217011FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83217011FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83217010FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83217009FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83217008FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83217007FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83217006FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83217005FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83217004FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83217003FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83217002FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83217001FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83217000FF}"

	:: Java Runtime Environment 1.6 (x64)
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416039FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416039F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416038FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416038F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416037FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416037F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416036FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416036F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416035FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416035F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416034FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416034F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416033FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416033F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416032FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416032F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416031FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416031F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416030FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416030F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416029FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416029F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416028FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416028F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416027FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416027F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416026FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416026F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416025FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416025F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416024FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416024F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416023FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F86416023F0}"

	:: Java Runtime Environment 1.6 (x86)
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216039FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216039F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216038FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216038F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216037FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216037F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216036FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216036F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216035FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216035F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216034FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216034F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216033FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216033F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216032FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216032F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216031FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216031F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216030FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216030F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216029FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216029F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216028FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216028F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216027FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216027F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216026FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216026F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216025FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216025F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216024FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216024F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216023FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216023F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216022FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216022F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216021FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216021F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216020FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216020F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216019FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216019F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216018FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216018F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216017FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216017F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216016FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216016F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216015FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216015F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216014FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216014F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216013FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216013F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216012FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216012F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216011FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216011F0}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216011FF}"
	@call :uninstall_helper "{26A24AE4-039D-4CA4-87B4-2F83216010F0}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0160070}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0160060}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0160050}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0160040}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0160030}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0160020}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0160010}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0160000}"

	:: Java Runtime Environment 1.5
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150220}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150210}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150200}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150190}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150180}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150170}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150160}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150150}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150140}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150130}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150120}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150110}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150100}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150090}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150080}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150070}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150060}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150050}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150040}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150030}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150020}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150010}"
	@call :uninstall_helper "{3248F0A8-6813-11D6-A77B-00B0D0150000}"

	:: Java Runtime Environment 1.4
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142190}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142180}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142170}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142160}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142150}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142140}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142130}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142120}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142110}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142100}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142090}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142080}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142070}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142060}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142050}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142040}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142030}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142020}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142010}"
	@call :uninstall_helper "{7148F0A8-6813-11D6-A77B-00B0D0142000}"

	:: Java Auto Updater
	@call :uninstall_helper "{4A03706F-666A-4037-7777-5F2748764D10}"

:finish
About these ads
  1. huehnerhose
    February 22, 2013 at 3:05 pm | #1

    Thanks! I was searching for this quite a time… Where did you get all the Java-IDs needed for uninstalling?
    Will you keep this script up-to-date?

    • February 22, 2013 at 7:50 pm | #2

      Hi, you can download all Java versions from the Oracle Website, so you’re able to check for the appropriate keys in the registry. However, if you take a closer look, you’ll see that they follow a logic so that you won’t have to install every single Java Version to find out the string. However, this bears the risk that not all sthe strings may be accurate. Kind regards!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: