View difference between Paste ID: ugwLzGXd and EaFke4vh
SHOW: | | - or go back to the newest paste.
1-
:: Purpose:       1. Nuke ALL versions of the Java Runtime, series 3 through 7, x86 and x64, and JavaFX
1+
:: Purpose:       1. Nuke ALL versions of JavaFX and the Java Runtime, series 3 through 7, x86 and x64
2
::                2. Leaves Java Development Kit installations intact
3
::                3. Reinstalls the latest JRE (if you want it to)
4
::                4. Puts the lotion on its skin.
5-
:: Requirements:  local administrative rights
5+
:: Requirements:  local administrative rights; WMI
6
:: Author:        vocatus on reddit.com/r/sysadmin and /r/usefulscripts
7
::                additional thanks to: 
8-
::                 - reddit.com/user/MrYiff          : testing which solved bug with OS_VERSION variable
8+
::                 - reddit.com/user/sdjason         : JRE reinstall functionality; selective process killing; et al
9
::                 - reddit.com/user/MrYiff          : bug fix related to OS_VERSION variable
10-
::                 - reddit.com/user/sdjason         : optional JRE reinstall functionality 
10+
11
::                 - forums.oracle.com/people/mattmn : a lot of stuff from his Java removal script
12-
:: History:       1.4.1 / FIX:          Re-enabled "echo off" statement at beginning of script
12+
:: History:       1.5.0 + FEATURE:      Added ability to choose whether or not to kill running Java processes before executing,
13-
::                      / FIX:          Fixed empty OS_VERSION variable on Vista/7/2008/8/2012 (MrYiff)
13+
::                                      along with a variable to specify an exit code to use                   (sdjason)
14
::                      + FEATURE:      Added ability to selectively reinstall x64 and x86 versions of the JRE (sdjason)
15
::                      * IMPROVEMENT:  Converted JRE 3 uninstaller section to a FOR loop
16
::                      * IMPROVEMENT:  Converted many commands into FOR loops with test cases to check if they should run or not (sdjason)
17
::                      * IMPROVEMENT:  File deletion commands now aren't run if their target doesn't exist.
18-
::                      + FILE CLEANUP: Added C:\Users*\AppData\LocalLow\Sun\Java\jre* (cannibalkitteh)
18+
::                                      This should reduce unecessary errors in the console and log.     (sdjason)
19-
::                      + FILE CLEANUP: Added C:\Users*\AppData\LocalLow\Sun\Java\AU   (cannibalkitteh)
19+
::                      / FIX:			Fixed incorrect search string in XP version of Java installer cache purge
20
::                1.4.1 / FIX:          Re-enabled "echo off" statement at beginning of script
21
::                      / FIX:          Fixed empty OS_VERSION variable on Vista/7/2008/8/2012           (MrYiff)
22-
::                      + FILE CLEANUP: Major overhaul,                                (mattm)
22+
23-
::                      + REGISTRY:     Added additional locations:                    (cannibalkitteh)
23+
24
::                      + FEATURE:      Added XP versions of a lot of the code
25
::                1.3   + FEATURE:      Added variables to reinstall Java after cleanup (off by default) (sdjason)
26
::                      + FILE CLEANUP: Added C:\Users*\AppData\LocalLow\Sun\Java\jre*                   (cannibalkitteh)
27
::                      + FILE CLEANUP: Added C:\Users*\AppData\LocalLow\Sun\Java\AU                     (cannibalkitteh)
28
::                1.2   + COMMENTS:     Improved a lot of commenting
29-
::                1.1   + Massive overhaul of functionality and logging
29+
30
::                      + FILE CLEANUP: Major overhaul to section                                        (mattm)
31
::                      + REGISTRY:     Added additional locations:                                      (cannibalkitteh)
32
::                        - HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
33
::                        - HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
34-
set VERSION=1.4.1
34+
35-
set UPDATED=2013-07-18
35+
36
::                      * LOGGING:      Minor improvements
37
::                1.1   + Overhaul of functionality and logging
38-
:: VARIABLES :: -- set these if you'd like
38+
39
40
:: Prep
41
@echo off
42
set VERSION=1.5.0
43
set UPDATED=2013-07-23
44
title Java Runtime Nuker v%VERSION% (%UPDATED%)
45
46
:::::::::::::::
47
:: VARIABLES :: -- set these if you'd like. The defaults should work fine though
48
:::::::::::::::
49
:: Rules for variables:
50
::  * NO quotes!                       (bad:  "c:\directory\path"       )
51-
:: Java re-install. Change to 'yes' if you want to reinstall Java after cleanup is done.
51+
52-
:: If you do, make sure to set the location, file name and arguments below!
52+
53-
set REINSTALL_JAVA=no
53+
54
::                                     (       \\172.16.1.5\share name  )
55-
:: The JRE installer must be in a place the script can find it (e.g. the same directory as the script)
55+
56-
set JAVA_LOCATION=%~dp0
56+
57-
set JAVA_BINARY=jre-7u25-windows-x64.exe
57+
58-
set JAVA_ARGUMENTS=/s /v"ADDLOCAL=ALL IEXPLORER=1 MOZILLA=1 JAVAUPDATE=0 REBOOT=suppress" /qn
58+
59
60-
:: =================================================================================== ::
60+
:: Force-close Java processes? Recommend leaving this set to 'yes' unless you
61-
::   Think of everything below this line like a feral badger: Look, but Do Not Touch   ::
61+
:: specifically want to abort the script if the target machine is currently using Java.
62-
:: =================================================================================== ::
62+
:: If you change this to 'no', the script will exit with an error code if it finds any running processes.
63
set FORCE_CLOSE_PROCESSES=yes
64-
:: Check if we're on XP, if so, set the flag. This affects some commands later,
64+
:: Exit code to use when FORCE_CLOSE_PROCESSES is "no" and a running Java process is detected
65-
:: because XP uses slightly different binaries for reg.exe and various other Windows utilities
65+
set FORCE_CLOSE_PROCESSES_EXIT_CODE=1618
66-
ver | find "XP"
66+
67
:: Java re-install. Do you want to reinstall Java afterwards?
68-
IF NOT %ERRORLEVEL%==0 set OS_VERSION=OTHER
68+
:: Change either of these to 'yes' if you want to reinstall Java after cleanup.
69
:: If you do, make sure to set the location, file names and arguments below!
70-
:: Force WMIC location
70+
set REINSTALL_JAVA_x64=no
71
set REINSTALL_JAVA_x86=no
72
73
:: The JRE installer must be in a place the script can find it (e.g. network path, same directory, etc)
74
:: JRE 64-bit reinstaller
75
set JAVA_LOCATION_x64=%~dp0
76
set JAVA_BINARY_x86=jre-7u25-windows-x64.exe
77
set JAVA_ARGUMENTS_x86=/s /v"ADDLOCAL=ALL IEXPLORER=1 MOZILLA=1 JAVAUPDATE=0 REBOOT=suppress" /qn
78
79
:: JRE 32-bit reinstaller
80
set JAVA_LOCATION_x86=%~dp0
81
set JAVA_BINARY_x86=jre-7u25-windows-x86.exe
82
set JAVA_ARGUMENTS_x86=/s /v"ADDLOCAL=ALL IEXPLORER=1 MOZILLA=1 JAVAUPDATE=0 REBOOT=suppress" /qn
83
84
85
:: =============================================================================================== ::
86
:: ======  Think of everything below this line like a feral badger: Look, but Do Not Touch  ====== ::
87
:: =============================================================================================== ::
88
89
90-
:: Do a quick check to make sure WMI is working, and if not, run a repair on it
90+
:: Check if we're on XP. This affects some commands later, because XP uses slightly
91-
wmic timezone
91+
:: different binaries for reg.exe and various other Windows utilities
92
set OS_VERSION=OTHER
93-
    echo %CUR_DATE% %TIME% ! WMI appears to be broken. Running WMI repair. This might take a minute, be patient...>> "%LOGPATH%\%LOGFILE%"
93+
ver | find /i "XP" >NUL
94-
    echo %CUR_DATE% %TIME% ! WMI appears to be broken. Running WMI repair. This might take a minute, be patient...
94+
95
96
:: Force WMIC location in case the system PATH is messed up
97
set WMIC=%WINDIR%\system32\wbem\wmic.exe
98
99
:: Create the log directory if it doesn't exist
100
if not exist %LOGPATH% mkdir %LOGPATH%
101
if exist "%LOGPATH%\%LOGFILE%" del "%LOGPATH%\%LOGFILE%"
102
103
:: Get the date into a format we can use (ISO standard date format)
104
set CUR_DATE=%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%
105
106
107
:::::::::::::::::::::
108
:: PREP AND CHECKS ::
109
:::::::::::::::::::::
110
echo.
111
echo  JAVA RUNTIME NUKER
112-
	
112+
113-
:: Kill all browsers and running Java instances first
113+
if %OS_VERSION%==XP echo. && echo  ! Windows XP detected, using alternate command set to compensate.
114-
echo %CUR_DATE% %TIME%   Killing all running browsers and Java instances...>> "%LOGPATH%\%LOGFILE%"
114+
115-
echo %CUR_DATE% %TIME%   Killing all running browsers and Java instances...
115+
116
echo %CUR_DATE% %TIME%   Beginning removal of Java Runtime Environments (series 3-7, x86 and x64) and JavaFX...
117-
    :: XP version of the task killer
117+
118-
    echo.
118+
:: Do a quick check to make sure WMI is working, and if not, repair it
119-
    tskill /a /v java >> "%LOGPATH%\%LOGFILE%"
119+
wmic timezone >NUL
120-
    tskill /a /v javaw >> "%LOGPATH%\%LOGFILE%"
120+
121-
    tskill /a /v javaws >> "%LOGPATH%\%LOGFILE%"
121+
    echo %CUR_DATE% %TIME% ! WMI appears to be broken. Running WMI repair. This might take a minute, please be patient...>> "%LOGPATH%\%LOGFILE%"
122-
    tskill /a /v jqs >> "%LOGPATH%\%LOGFILE%"
122+
    echo %CUR_DATE% %TIME% ! WMI appears to be broken. Running WMI repair. This might take a minute, please be patient...
123-
    tskill /a /v jusched >> "%LOGPATH%\%LOGFILE%"
123+
124-
    tskill /a /v iexplore >> "%LOGPATH%\%LOGFILE%"
124+
125-
    tskill /a /v iexplorer >> "%LOGPATH%\%LOGFILE%"
125+
126-
    tskill /a /v firefox >> "%LOGPATH%\%LOGFILE%"
126+
127-
    tskill /a /v chrome >> "%LOGPATH%\%LOGFILE%"
127+
128-
    echo.
128+
129-
) ELSE (
129+
130-
    :: All other Windows versions
130+
131-
    echo.
131+
132-
    taskkill /f /im java.exe /T >> "%LOGPATH%\%LOGFILE%"
132+
133-
    taskkill /f /im javaw.exe /T >> "%LOGPATH%\%LOGFILE%"
133+
134-
    taskkill /f /im javaws.exe /T >> "%LOGPATH%\%LOGFILE%"
134+
135-
    taskkill /f /im jqs.exe /T >> "%LOGPATH%\%LOGFILE%"
135+
136-
    taskkill /f /im jusched.exe /T >> "%LOGPATH%\%LOGFILE%"
136+
137-
    taskkill /f /im iexplore.exe /T >> "%LOGPATH%\%LOGFILE%"
137+
138-
    taskkill /f /im iexplorer.exe /T >> "%LOGPATH%\%LOGFILE%"
138+
139-
    taskkill /f /im firefox.exe /T >> "%LOGPATH%\%LOGFILE%"
139+
)
140-
    taskkill /f /im chrome.exe /T >> "%LOGPATH%\%LOGFILE%"
140+
141-
    echo.
141+
142
:::::::::::::::::::::::::::
143
:: FORCE-CLOSE PROCESSES :: -- Do we want to kill Java before running? If so, this is where it happens
144
:::::::::::::::::::::::::::
145-
	:::::::::::::::::::::::::
145+
if %FORCE_CLOSE_PROCESSES%==yes (
146
	:: Kill all browsers and running Java instances
147-
:::::::::::::::::::::::::    removing Java, before resorting to more painstaking methods later
147+
	echo %CUR_DATE% %TIME%   Looking for and closing all running browsers and Java instances...>> "%LOGPATH%\%LOGFILE%"
148
	echo %CUR_DATE% %TIME%   Looking for and closing all running browsers and Java instances...
149
	if %OS_VERSION%==XP (
150
		:: XP version of the task killer
151
		:: this loop contains the processes we should kill
152
		echo.
153-
:: This makes it easy to catch ALL of them through liberal use of WMIC wildcards ("_" is single character, "%" is any number of characters)
153+
		FOR %%i IN (java,javaw,javaws,jqs,jusched,iexplore,iexplorer,firefox,chrome,palemoon) DO (
154-
:: Additionally, JRE 6 introduced 64-bit runtimes, so in addition to the two-digit Update revision number (e.g. update 34), we also now 
154+
			echo Searching for %%i.exe...
155-
:: check for the architecture type, which always equals '32' or '64'. First wildcard is the architecture, second is the revision/update number.
155+
			tskill /a /v %%i >> "%LOGPATH%\%LOGFILE%" 2>NUL
156
		)
157
		echo.
158
	) else (
159
		:: 7/8/2008/2008R2/2012/etc version of the task killer
160
		:: this loop contains the processes we should kill
161
		echo.
162
		FOR %%i IN (java,javaw,javaws,jqs,jusched,iexplore,iexplorer,firefox,chrome,palemoon) DO (
163
			echo Searching for %%i.exe...
164
			taskkill /f /im %%i.exe /T >> "%LOGPATH%\%LOGFILE%" 2>NUL
165
		)
166
		echo.
167
	)
168
)
169
170
:: If we DON'T want to force-close Java, then check for possible running Java processes and abort the script if we find any
171
if %FORCE_CLOSE_PROCESSES%==no (
172
	echo %CUR_DATE% %TIME%   Variable FORCE_CLOSE_PROCESSES is set to '%FORCE_CLOSE_PROCESSES%'. Checking for running processes before execution.>> "%LOGPATH%\%LOGFILE%"
173
	echo %CUR_DATE% %TIME%   Variable FORCE_CLOSE_PROCESSES is set to '%FORCE_CLOSE_PROCESSES%'. Checking for running processes before execution.
174
175
	:: Don't ask...
176
	:: Okay so basically we loop through this list of processes, and for each one we dump the result of the search in the '%%a' variable. 
177
	:: Then, we check that variable, and if it's not null (e.g. FIND.exe found something) then we abort the script, returning the exit code
178
	:: specified at the beginning of the script.
179
	:: Normally you'd use ERRORLEVEL for this, but because it is very flaky (it doesn't always get set, even when it should) we instead
180-
:: JRE 3
180+
	:: resort to using this method of dumping the results in a variable and checking it later.
181
	FOR %%i IN (java,javaw,javaws,jqs,jusched,iexplore,iexplorer,firefox,chrome,palemoon) DO (
182
		echo %CUR_DATE% %TIME%   Searching for %%i.exe...
183-
:: This version is so old we have to resort to a different method of removing it
183+
		for /f "delims=" %%a in ('tasklist ^| find /i "%%i"') do (
184-
:: Java 2 Runtime Environment Standard Edition v1.3.1_25-00
184+
			if not [%%a]==[] (
185-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_25\Uninst.isu" -a 2>NUL
185+
				echo %CUR_DATE% %TIME% ! ERROR: Process '%%i' is currently running, aborting.>> "%LOGPATH%\%LOGFILE%"
186-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_24\Uninst.isu" -a 2>NUL
186+
				echo %CUR_DATE% %TIME% ! ERROR: Process '%%i' is currently running, aborting.
187-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_23\Uninst.isu" -a 2>NUL
187+
				exit /b %FORCE_CLOSE_PROCESSES_EXIT_CODE%
188-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_22\Uninst.isu" -a 2>NUL
188+
			)
189-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_21\Uninst.isu" -a 2>NUL
189+
		)
190-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_20\Uninst.isu" -a 2>NUL
190+
	)
191-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_19\Uninst.isu" -a 2>NUL
191+
	:: If we made it this far, we didn't find anything, so we can go ahead
192-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_18\Uninst.isu" -a 2>NUL
192+
	echo %CUR_DATE% %TIME%   All clear, no running processes found. Going ahead with removal...>> "%LOGPATH%\%LOGFILE%"
193-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_17\Uninst.isu" -a 2>NUL
193+
	echo %CUR_DATE% %TIME%   All clear, no running processes found. Going ahead with removal...
194-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_16\Uninst.isu" -a 2>NUL
194+
)
195-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_15\Uninst.isu" -a 2>NUL
195+
196-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_14\Uninst.isu" -a 2>NUL
196+
197-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_13\Uninst.isu" -a 2>NUL
197+
:::::::::::::::::::::::::
198-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_12\Uninst.isu" -a 2>NUL
198+
199-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_11\Uninst.isu" -a 2>NUL
199+
:::::::::::::::::::::::::    removing Java, and then resort to more painstaking methods later
200-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_10\Uninst.isu" -a 2>NUL
200+
201-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_09\Uninst.isu" -a 2>NUL
201+
202-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_08\Uninst.isu" -a 2>NUL
202+
203-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_07\Uninst.isu" -a 2>NUL
203+
204-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_06\Uninst.isu" -a 2>NUL
204+
205-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_05\Uninst.isu" -a 2>NUL
205+
:: This makes it easy to catch ALL of them through liberal use of WMI wildcards ("_" is single character, "%" is any number of characters)
206-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_04\Uninst.isu" -a 2>NUL
206+
:: Additionally, JRE 6 introduced 64-bit runtimes, so in addition to the two-digit Update XX revision number, we also check for the architecture 
207-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_03\Uninst.isu" -a 2>NUL
207+
:: type, which always equals '32' or '64'. The first wildcard is the architecture, the second is the revision/update number.
208-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_02\Uninst.isu" -a 2>NUL
208+
209-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3.1_01\Uninst.isu" -a 2>NUL
209+
210-
%SystemRoot%\IsUninst.exe -f"%SystemDrive%\Program Files\JavaSoft\JRE\1.3\Uninst.isu" -a 2>NUL
210+
211
echo %CUR_DATE% %TIME%   JRE 7...
212-
:: Run wildcard uninstallers
212+
213-
echo %CUR_DATE% %TIME%   Now running WMIC wildcard catchall uninstallation...>> "%LOGPATH%\%LOGFILE%"
213+
214-
echo %CUR_DATE% %TIME%   Now running WMIC wildcard catchall uninstallation...
214+
215
echo %CUR_DATE% %TIME%   JRE 6...>> "%LOGPATH%\%LOGFILE%"
216
echo %CUR_DATE% %TIME%   JRE 6...
217
:: 1st line is for updates 23-xx, after 64-bit runtimes were introduced.
218
:: 2nd line is for updates 1-22, before Oracle released 64-bit JRE 6 runtimes
219
%WMIC% product where "IdentifyingNumber like '{26A24AE4-039D-4CA4-87B4-2F8__160__FF}'" call uninstall /nointeractive>> "%LOGPATH%\%LOGFILE%"
220
%WMIC% product where "IdentifyingNumber like '{3248F0A8-6813-11D6-A77B-00B0D0160__0}'" call uninstall /nointeractive>> "%LOGPATH%\%LOGFILE%"
221
222
:: JRE 5
223
echo %CUR_DATE% %TIME%   JRE 5...>> "%LOGPATH%\%LOGFILE%"
224
echo %CUR_DATE% %TIME%   JRE 5...
225-
if %OS_VERSION%==XP(
225+
226-
    echo %CUR_DATE% %TIME%   Registry cleanup doesn't work on Windows XP, skipping...>> "%LOGPATH%\%LOGFILE%"
226+
227-
    echo %CUR_DATE% %TIME%   Registry cleanup doesn't work on Windows XP, skipping...
227+
228
echo %CUR_DATE% %TIME%   JRE 4...>> "%LOGPATH%\%LOGFILE%"
229-
    :: All other versions of Windows
229+
230-
    echo %CUR_DATE% %TIME%   Commencing registry cleanup...>> "%LOGPATH%\%LOGFILE%"
230+
231-
    echo %CUR_DATE% %TIME%   Commencing registry cleanup...
231+
232-
    echo %CUR_DATE% %TIME%   Searching for residual registry keys...>> "%LOGPATH%\%LOGFILE%"
232+
:: JRE 3 (AKA "Java 2 Runtime Environment Standard Edition" v1.3.1_00-25)
233-
    echo %CUR_DATE% %TIME%   Searching for residual registry keys...
233+
234
echo %CUR_DATE% %TIME%   JRE 3 (AKA Java 2 Runtime v1.3.xx)...
235-
    :: Search MSIExec installer class hive for keys
235+
:: This version is so old we have to resort to different methods of removing it
236-
    echo %CUR_DATE% %TIME%   Looking in HKLM\software\classes\installer\products...>> "%LOGPATH%\%LOGFILE%"
236+
:: Loop through each sub-version
237-
    echo %CUR_DATE% %TIME%   Looking in HKLM\software\classes\installer\products...
237+
FOR %%i IN (01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25) DO (
238-
    reg query HKLM\software\classes\installer\products /f "J2SE Runtime" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
238+
	%SystemRoot%\IsUninst.exe -f"%ProgramFiles%\JavaSoft\JRE\1.3.1_%%i\Uninst.isu" -a 2>NUL
239-
    reg query HKLM\software\classes\installer\products /f "Java(TM) 6 Update" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
239+
	%SystemRoot%\IsUninst.exe -f"%ProgramFiles(x86)%\JavaSoft\JRE\1.3.1_%%i\Uninst.isu" -a 2>NUL
240-
    reg query HKLM\software\classes\installer\products /f "Java 7" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
240+
)
241-
    reg query HKLM\software\classes\installer\products /f "Java*Runtime" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
241+
:: This one wouldn't fit in the loop above
242
%SystemRoot%\IsUninst.exe -f"%ProgramFiles%\JavaSoft\JRE\1.3\Uninst.isu" -a 2>NUL
243-
    :: Search the Add/Remove programs list (this helps with broken Java installations)
243+
%SystemRoot%\IsUninst.exe -f"%ProgramFiles(x86)%\JavaSoft\JRE\1.3\Uninst.isu" -a 2>NUL
244-
    echo %CUR_DATE% %TIME%   Looking in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall...>> "%LOGPATH%\%LOGFILE%"
244+
245-
    echo %CUR_DATE% %TIME%   Looking in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall...
245+
:: Wildcard uninstallers
246-
    reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /f "J2SE Runtime" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
246+
echo %CUR_DATE% %TIME%   Specific targeting done. Now running WMIC wildcard catchall uninstallation...>> "%LOGPATH%\%LOGFILE%"
247-
    reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /f "Java(TM) 6 Update" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
247+
echo %CUR_DATE% %TIME%   Specific targeting done. Now running WMIC wildcard catchall uninstallation...
248-
    reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /f "Java 7" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
248+
249-
    reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /f "Java*Runtime" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
249+
250
%WMIC% product where "name like 'JavaFX%%'" call uninstall /nointeractive>> "%LOGPATH%\%LOGFILE%"
251-
    :: Search the Add/Remove programs list, x86/Wow64 node (this helps with broken Java installations)
251+
252-
    echo %CUR_DATE% %TIME%   Looking in HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall...>> "%LOGPATH%\%LOGFILE%"
252+
253-
    echo %CUR_DATE% %TIME%   Looking in HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall...
253+
254-
    reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /f "J2SE Runtime" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
254+
255-
    reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /f "Java(TM) 6 Update" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
255+
256-
    reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /f "Java 7" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
256+
257-
    reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /f "Java*Runtime" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
257+
258
:: If we're on XP we skip this entire block due to differences in the reg.exe binary
259
if '%OS_VERSION%'=='XP' (
260-
    :: List the leftover registry keys
260+
    echo %CUR_DATE% %TIME% ! Registry cleanup doesn't work on Windows XP. Skipping...>> "%LOGPATH%\%LOGFILE%"
261-
    echo %CUR_DATE% %TIME%   Found these keys...>> "%LOGPATH%\%LOGFILE%"
261+
    echo %CUR_DATE% %TIME% ! Registry cleanup doesn't work on Windows XP. Skipping...
262-
    echo %CUR_DATE% %TIME%   Found these keys...
262+
	goto file_cleanup
263-
    echo.>> "%LOGPATH%\%LOGFILE%"
263+
	)
264-
    echo.
264+
265-
    type %TEMP%\java_purge_registry_keys.txt>> "%LOGPATH%\%LOGFILE%"
265+
echo %CUR_DATE% %TIME%   Commencing registry cleanup...>> "%LOGPATH%\%LOGFILE%"
266-
    type %TEMP%\java_purge_registry_keys.txt
266+
echo %CUR_DATE% %TIME%   Commencing registry cleanup...
267-
    echo.>> "%LOGPATH%\%LOGFILE%"
267+
echo %CUR_DATE% %TIME%   Searching for residual registry keys...>> "%LOGPATH%\%LOGFILE%"
268-
    echo.
268+
echo %CUR_DATE% %TIME%   Searching for residual registry keys...
269
270-
    :: Backup the various registry keys that will get deleted (if they exist)
270+
:: Search MSIExec installer class hive for keys
271-
    :: We do this mainly because we're using wildcards, so we want a method to roll back if we accidentally nuke the wrong thing
271+
echo %CUR_DATE% %TIME%   Looking in HKLM\software\classes\installer\products...>> "%LOGPATH%\%LOGFILE%"
272-
    echo %CUR_DATE% %TIME%   Backing up keys...>> "%LOGPATH%\%LOGFILE%"
272+
echo %CUR_DATE% %TIME%   Looking in HKLM\software\classes\installer\products...
273-
    echo %CUR_DATE% %TIME%   Backing up keys...
273+
reg query HKLM\software\classes\installer\products /f "J2SE Runtime" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
274-
    if exist "%TEMP%\java_purge_registry_backup" rmdir /s /q "%TEMP%\java_purge_registry_backup" >NUL
274+
reg query HKLM\software\classes\installer\products /f "Java(TM) 6 Update" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
275-
    mkdir %TEMP%\java_purge_registry_backup >NUL
275+
reg query HKLM\software\classes\installer\products /f "Java 7" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
276-
    :: This line walks through the file we generated and dumps each key to a file
276+
reg query HKLM\software\classes\installer\products /f "Java*Runtime" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
277-
    for /f "tokens=* delims= " %%a in (%TEMP%\java_purge_registry_keys.txt) do (reg query %%a) >> %TEMP%\java_purge_registry_backup\java_reg_keys_1.bak
277+
278
:: Search the Add/Remove programs list (this helps with broken Java installations)
279-
    echo.
279+
echo %CUR_DATE% %TIME%   Looking in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall...>> "%LOGPATH%\%LOGFILE%"
280-
    echo %CUR_DATE% %TIME%   Keys backed up to %TEMP%\java_purge_registry_backup\ >> "%LOGPATH%\%LOGFILE%"
280+
echo %CUR_DATE% %TIME%   Looking in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall...
281-
    echo %CUR_DATE% %TIME%   Keys backed up to %TEMP%\java_purge_registry_backup\
281+
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /f "J2SE Runtime" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
282-
    echo %CUR_DATE% %TIME%   This directory will be deleted at next reboot, so get it now if you need it! >> "%LOGPATH%\%LOGFILE%"
282+
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /f "Java(TM) 6 Update" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
283-
    echo %CUR_DATE% %TIME%   This directory will be deleted at next reboot, so get it now if you need it!
283+
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /f "Java 7" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
284
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /f "Java*Runtime" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
285-
    :: Purge the keys
285+
286-
    echo %CUR_DATE% %TIME%   Purging keys...>> "%LOGPATH%\%LOGFILE%"
286+
:: Search the Add/Remove programs list, x86/Wow64 node (this helps with broken Java installations)
287-
    echo %CUR_DATE% %TIME%   Purging keys...
287+
echo %CUR_DATE% %TIME%   Looking in HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall...>> "%LOGPATH%\%LOGFILE%"
288-
    echo.
288+
echo %CUR_DATE% %TIME%   Looking in HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall...
289-
    :: This line walks through the file we generated and deletes each key listed
289+
reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /f "J2SE Runtime" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
290-
    for /f "tokens=* delims= " %%a in (%TEMP%\java_purge_registry_keys.txt) do reg delete %%a /va /f>> "%LOGPATH%\%LOGFILE%"
290+
reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /f "Java(TM) 6 Update" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
291
reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /f "Java 7" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
292-
    :: These lines delete some specific Java locations
292+
reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /f "Java*Runtime" /s | find "HKEY_LOCAL_MACHINE" >> %TEMP%\java_purge_registry_keys.txt
293-
    :: These keys AREN'T backed up because here we are specifically targeting known Java keys, whereas
293+
294-
    :: above we were nuking keys based on wildcards, so those need backups in case we nuke something we didn't want to.
294+
:: List the leftover registry keys
295
echo %CUR_DATE% %TIME%   Found these keys...>> "%LOGPATH%\%LOGFILE%"
296-
    :: Delete keys for 32-bit Java installations on a 64-bit copy of Windows
296+
echo %CUR_DATE% %TIME%   Found these keys...
297-
    reg delete "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Auto Update" /va /f>> "%LOGPATH%\%LOGFILE%"
297+
echo.>> "%LOGPATH%\%LOGFILE%"
298-
    reg delete "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Plug-in" /va /f>> "%LOGPATH%\%LOGFILE%"
298+
299-
    reg delete "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment" /va /f>> "%LOGPATH%\%LOGFILE%"
299+
type %TEMP%\java_purge_registry_keys.txt>> "%LOGPATH%\%LOGFILE%"
300-
    reg delete "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Update" /va /f>> "%LOGPATH%\%LOGFILE%"
300+
type %TEMP%\java_purge_registry_keys.txt
301-
    reg delete "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Web Start" /va /f>> "%LOGPATH%\%LOGFILE%"
301+
echo.>> "%LOGPATH%\%LOGFILE%"
302-
    reg delete "HKLM\SOFTWARE\Wow6432Node\JreMetrics" /va /f>> "%LOGPATH%\%LOGFILE%"
302+
303
304-
    :: Delete keys for for 32-bit and 64-bit Java installations on matching Windows architecture
304+
:: Backup the various registry keys that will get deleted (if they exist)
305-
    reg delete "HKLM\SOFTWARE\JavaSoft\Auto Update" /va /f>> "%LOGPATH%\%LOGFILE%"
305+
:: We do this mainly because we're using wildcards, so we want a method to roll back if we accidentally nuke the wrong thing
306-
    reg delete "HKLM\SOFTWARE\JavaSoft\Java Plug-in" /va /f>> "%LOGPATH%\%LOGFILE%"
306+
echo %CUR_DATE% %TIME%   Backing up keys...>> "%LOGPATH%\%LOGFILE%"
307-
    reg delete "HKLM\SOFTWARE\JavaSoft\Java Runtime Environment" /va /f>> "%LOGPATH%\%LOGFILE%"
307+
echo %CUR_DATE% %TIME%   Backing up keys...
308-
    reg delete "HKLM\SOFTWARE\JavaSoft\Java Update" /va /f>> "%LOGPATH%\%LOGFILE%"
308+
if exist "%TEMP%\java_purge_registry_backup" rmdir /s /q "%TEMP%\java_purge_registry_backup" 2>NUL
309-
    reg delete "HKLM\SOFTWARE\JavaSoft\Java Web Start" /va /f>> "%LOGPATH%\%LOGFILE%"
309+
mkdir %TEMP%\java_purge_registry_backup >NUL
310-
    reg delete "HKLM\SOFTWARE\JreMetrics" /va /f>> "%LOGPATH%\%LOGFILE%"
310+
:: This line walks through the file we generated and dumps each key to a file
311
for /f "tokens=* delims= " %%a in (%TEMP%\java_purge_registry_keys.txt) do (reg query %%a) >> %TEMP%\java_purge_registry_backup\java_reg_keys_1.bak
312-
    echo.
312+
313-
    echo %CUR_DATE% %TIME%   Keys purged.>> "%LOGPATH%\%LOGFILE%"
313+
314-
    echo %CUR_DATE% %TIME%   Keys purged.
314+
echo %CUR_DATE% %TIME%   Keys backed up to %TEMP%\java_purge_registry_backup\ >> "%LOGPATH%\%LOGFILE%"
315-
    echo %CUR_DATE% %TIME%   Registry cleanup done.>> "%LOGPATH%\%LOGFILE%"
315+
echo %CUR_DATE% %TIME%   Keys backed up to %TEMP%\java_purge_registry_backup\
316-
    echo %CUR_DATE% %TIME%   Registry cleanup done.
316+
echo %CUR_DATE% %TIME%   This directory will be deleted at next reboot, so get it now if you need it! >> "%LOGPATH%\%LOGFILE%"
317-
    echo.
317+
echo %CUR_DATE% %TIME%   This directory will be deleted at next reboot, so get it now if you need it!
318
319
:: Purge the keys
320
echo %CUR_DATE% %TIME%   Purging keys...>> "%LOGPATH%\%LOGFILE%"
321
echo %CUR_DATE% %TIME%   Purging keys...
322
echo.
323
:: This line walks through the file we generated and deletes each key listed
324
for /f "tokens=* delims= " %%a in (%TEMP%\java_purge_registry_keys.txt) do reg delete %%a /va /f >> "%LOGPATH%\%LOGFILE%" 2>NUL
325
326
:: These lines delete some specific Java locations
327
:: These keys AREN'T backed up because these are specific, known Java keys, whereas above we were nuking
328
:: keys based on wildcards, so those need backups in case we nuke something we didn't want to.
329
330-
del /F /Q %WINDIR%\tasks\Java*.job>> "%LOGPATH%\%LOGFILE%"
330+
:: Delete keys for 32-bit Java installations on a 64-bit copy of Windows
331-
del /F /Q %WINDIR%\System32\tasks\Java*.job>> "%LOGPATH%\%LOGFILE%"
331+
reg delete "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Auto Update" /va /f>> "%LOGPATH%\%LOGFILE%" 2>NUL
332-
del /F /Q %WINDIR%\SysWOW64\tasks\Java*.job>> "%LOGPATH%\%LOGFILE%"
332+
reg delete "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Plug-in" /va /f>> "%LOGPATH%\%LOGFILE%" 2>NUL
333
reg delete "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment" /va /f>> "%LOGPATH%\%LOGFILE%" 2>NUL
334
reg delete "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Update" /va /f>> "%LOGPATH%\%LOGFILE%" 2>NUL
335-
:: Kill the accursed Java Quickstarter and Updater
335+
reg delete "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Web Start" /va /f>> "%LOGPATH%\%LOGFILE%" 2>NUL
336-
echo %CUR_DATE% %TIME%   De-registering and removing Java Quickstarter and Updater...>> "%LOGPATH%\%LOGFILE%"
336+
reg delete "HKLM\SOFTWARE\Wow6432Node\JreMetrics" /va /f>> "%LOGPATH%\%LOGFILE%" 2>NUL
337-
echo %CUR_DATE% %TIME%   De-registering and removing Java Quickstarter and Updater...
337+
338-
net stop JavaQuickStarterService>> "%LOGPATH%\%LOGFILE%"
338+
:: Delete keys for for 32-bit and 64-bit Java installations on matching Windows architecture
339-
sc delete JavaQuickStarterService>> "%LOGPATH%\%LOGFILE%"
339+
reg delete "HKLM\SOFTWARE\JavaSoft\Auto Update" /va /f>> "%LOGPATH%\%LOGFILE%" 2>NUL
340-
net stop jusched>> "%LOGPATH%\%LOGFILE%"
340+
reg delete "HKLM\SOFTWARE\JavaSoft\Java Plug-in" /va /f>> "%LOGPATH%\%LOGFILE%" 2>NUL
341-
sc delete jusched>> "%LOGPATH%\%LOGFILE%"
341+
reg delete "HKLM\SOFTWARE\JavaSoft\Java Runtime Environment" /va /f>> "%LOGPATH%\%LOGFILE%" 2>NUL
342-
"%ProgramFiles(x86)%\Java\jre6\bin\jqs.exe" -disable>> "%LOGPATH%\%LOGFILE%"
342+
reg delete "HKLM\SOFTWARE\JavaSoft\Java Update" /va /f>> "%LOGPATH%\%LOGFILE%" 2>NUL
343-
"%ProgramFiles(x86)%\Java\jre7\bin\jqs.exe" -disable>> "%LOGPATH%\%LOGFILE%"
343+
reg delete "HKLM\SOFTWARE\JavaSoft\Java Web Start" /va /f>> "%LOGPATH%\%LOGFILE%" 2>NUL
344-
"%ProgramFiles%\Java\jre6\bin\jqs.exe" -disable>> "%LOGPATH%\%LOGFILE%"
344+
reg delete "HKLM\SOFTWARE\JreMetrics" /va /f>> "%LOGPATH%\%LOGFILE%" 2>NUL
345-
"%ProgramFiles%\Java\jre7\bin\jqs.exe" -disable>> "%LOGPATH%\%LOGFILE%"
345+
346-
"%ProgramFiles(x86)%\Java\jre6\bin\jqs.exe" -unregister>> "%LOGPATH%\%LOGFILE%"
346+
347-
"%ProgramFiles(x86)%\Java\jre7\bin\jqs.exe" -unregister>> "%LOGPATH%\%LOGFILE%"
347+
echo %CUR_DATE% %TIME%   Keys purged.>> "%LOGPATH%\%LOGFILE%"
348-
"%ProgramFiles%\Java\jre6\bin\jqs.exe" -unregister>> "%LOGPATH%\%LOGFILE%"
348+
echo %CUR_DATE% %TIME%   Keys purged.
349-
"%ProgramFiles%\Java\jre7\bin\jqs.exe" -unregister>> "%LOGPATH%\%LOGFILE%"
349+
echo %CUR_DATE% %TIME%   Registry cleanup done.>> "%LOGPATH%\%LOGFILE%"
350
echo %CUR_DATE% %TIME%   Registry cleanup done.
351
echo.
352
353
354-
echo %CUR_DATE% %TIME%   Removing "%ProgramFiles(x86)%\Java\jre*" directories...>> "%LOGPATH%\%LOGFILE%"
354+
355-
echo %CUR_DATE% %TIME%   Removing "%ProgramFiles(x86)%\Java\jre*" directories...
355+
356-
for /D /R "%ProgramFiles(x86)%\Java\" %%X in (j2re*) DO RMDIR /S /Q "%%X">> "%LOGPATH%\%LOGFILE%"
356+
357-
for /D /R "%ProgramFiles(x86)%\Java\" %%X in (jre*) DO RMDIR /S /Q "%%X">> "%LOGPATH%\%LOGFILE%"
357+
:file_cleanup
358-
rmdir /S /Q "%ProgramFiles(x86)%\JavaSoft\JRE">> "%LOGPATH%\%LOGFILE%"
358+
359
echo %CUR_DATE% %TIME%   Commencing file and directory cleanup...
360
361
:: Kill accursed Java tasks in Task Scheduler
362
echo %CUR_DATE% %TIME%   Removing Java tasks from the Windows Task Scheduler...>> "%LOGPATH%\%LOGFILE%"
363-
for /D /R "%ProgramFiles%\Java\" %%X in (j2re*) DO RMDIR /S /Q "%%X">> "%LOGPATH%\%LOGFILE%"
363+
364-
for /D /R "%ProgramFiles%\Java\" %%X in (jre*) DO RMDIR /S /Q "%%X">> "%LOGPATH%\%LOGFILE%"
364+
if exist %WINDIR%\tasks\Java*.job del /F /Q %WINDIR%\tasks\Java*.job >> "%LOGPATH%\%LOGFILE%"
365-
rmdir /S /Q "%ProgramFiles%\JavaSoft\JRE">> "%LOGPATH%\%LOGFILE%"
365+
if exist %WINDIR%\System32\tasks\Java*.job del /F /Q %WINDIR%\System32\tasks\Java*.job >> "%LOGPATH%\%LOGFILE%"
366
if exist %WINDIR%\SysWOW64\tasks\Java*.job del /F /Q %WINDIR%\SysWOW64\tasks\Java*.job >> "%LOGPATH%\%LOGFILE%"
367-
:: Nuke Java installer cache ( thanks to reddit.com/user/cannibalkitteh )
367+
368
369
:: Kill the accursed Java Quickstarter service
370-
ver | find "XP"
370+
sc query JavaQuickStarterService >NUL
371-
IF %ERRORLEVEL%==0 (
371+
if not %ERRORLEVEL%==1060 (
372-
    ::::::::::::::::
372+
	echo %CUR_DATE% %TIME%   De-registering and removing Java Quickstarter service...>> "%LOGPATH%\%LOGFILE%"
373-
    :: XP version ::
373+
	echo %CUR_DATE% %TIME%   De-registering and removing Java Quickstarter service...
374-
    ::::::::::::::::
374+
	net stop JavaQuickStarterService >> "%LOGPATH%\%LOGFILE%" 2>NUL
375
	sc delete JavaQuickStarterService >> "%LOGPATH%\%LOGFILE%" 2>NUL
376
)
377-
    for /f "tokens=* delims= " %%a in (%TEMP%\userlist.txt) DO RMDIR /S /Q "%SystemDrive%\Users\%%a\AppData\LocalLow\Sun\Java\AU">> "%LOGPATH%\%LOGFILE%"
377+
378-
    for /D /R "%SystemDrive%\Documents and Settings\" %%X in (jre*) DO RMDIR /S /Q "%%X">> "%LOGPATH%\%LOGFILE%"
378+
:: Kill the accursed Java Update Scheduler service
379-
) ELSE (
379+
sc query jusched >NUL
380-
    ::::::::::::::::::::::::::
380+
if not %ERRORLEVEL%==1060 (
381-
    :: Vista and up version ::
381+
	echo %CUR_DATE% %TIME%   De-registering and removing Java Update Scheduler service...>> "%LOGPATH%\%LOGFILE%"
382-
    ::::::::::::::::::::::::::
382+
	echo %CUR_DATE% %TIME%   De-registering and removing Java Update Scheduler service...
383
	net stop jusched >> "%LOGPATH%\%LOGFILE%" 2>NUL
384
	sc delete jusched >> "%LOGPATH%\%LOGFILE%" 2>NUL
385-
    for /f "tokens=* delims= " %%a in (%TEMP%\userlist.txt) DO RMDIR /S /Q "%SystemDrive%\Users\%%a\AppData\LocalLow\Sun\Java\AU">> "%LOGPATH%\%LOGFILE%"
385+
)
386
387-
    for /D /R "%SystemDrive%\Users" %%X in (jre*) DO RMDIR /S /Q "%%X">> "%LOGPATH%\%LOGFILE%"
387+
:: This is the Oracle method of disabling the Java services. 99% of the time these commands aren't required. 
388
if exist "%ProgramFiles(x86)%\Java\jre6\bin\jqs.exe" "%ProgramFiles(x86)%\Java\jre6\bin\jqs.exe" -disable>> "%LOGPATH%\%LOGFILE%"
389
if exist "%ProgramFiles(x86)%\Java\jre7\bin\jqs.exe" "%ProgramFiles(x86)%\Java\jre7\bin\jqs.exe" -disable>> "%LOGPATH%\%LOGFILE%"
390
if exist "%ProgramFiles%\Java\jre6\bin\jqs.exe" "%ProgramFiles%\Java\jre6\bin\jqs.exe" -disable>> "%LOGPATH%\%LOGFILE%"
391
if exist "%ProgramFiles%\Java\jre7\bin\jqs.exe" "%ProgramFiles%\Java\jre7\bin\jqs.exe" -disable>> "%LOGPATH%\%LOGFILE%"
392
if exist "%ProgramFiles(x86)%\Java\jre6\bin\jqs.exe" "%ProgramFiles(x86)%\Java\jre6\bin\jqs.exe" -unregister>> "%LOGPATH%\%LOGFILE%"
393
if exist "%ProgramFiles(x86)%\Java\jre7\bin\jqs.exe" "%ProgramFiles(x86)%\Java\jre7\bin\jqs.exe" -unregister>> "%LOGPATH%\%LOGFILE%"
394-
del /F /Q %SystemDrive%\1033.mst>> "%LOGPATH%\%LOGFILE%"
394+
if exist "%ProgramFiles%\Java\jre6\bin\jqs.exe" "%ProgramFiles%\Java\jre6\bin\jqs.exe" -unregister>> "%LOGPATH%\%LOGFILE%"
395-
del /F /S /Q "%SystemDrive%\J2SE Runtime Environment*">> "%LOGPATH%\%LOGFILE%"
395+
if exist "%ProgramFiles%\Java\jre7\bin\jqs.exe" "%ProgramFiles%\Java\jre7\bin\jqs.exe" -unregister>> "%LOGPATH%\%LOGFILE%"
396
msiexec.exe /x {4A03706F-666A-4037-7777-5F2748764D10} /qn /norestart
397
398
:: Nuke 32-bit Java installation directories
399
if exist "%ProgramFiles(x86)%" (
400
	echo %CUR_DATE% %TIME%   Removing "%ProgramFiles(x86)%\Java\jre*" directories...>> "%LOGPATH%\%LOGFILE%"
401
	echo %CUR_DATE% %TIME%   Removing "%ProgramFiles(x86)%\Java\jre*" directories...
402
	for /D /R "%ProgramFiles(x86)%\Java\" %%x in (j2re*) do if exist "%%x" rmdir /S /Q "%%x">> "%LOGPATH%\%LOGFILE%"
403-
:: Check if we wanted to install a new version of the JRE. If we didn't, then go ahead and exit.
403+
	for /D /R "%ProgramFiles(x86)%\Java\" %%x in (jre*) do if exist "%%x" rmdir /S /Q "%%x">> "%LOGPATH%\%LOGFILE%"
404-
IF %REINSTALL_JAVA%==yes (
404+
	if exist "%ProgramFiles(x86)%\JavaSoft\JRE" rmdir /S /Q "%ProgramFiles(x86)%\JavaSoft\JRE" >> "%LOGPATH%\%LOGFILE%"
405-
    echo %CUR_DATE% %TIME% ! Variable "REINSTALL_JAVA" was set to 'yes'. Now installing %JAVA_BINARY%...>> "%LOGPATH%\%LOGFILE%"
405+
)
406-
    echo %CUR_DATE% %TIME% ! Variable "REINSTALL_JAVA" was set to 'yes'. Now installing %JAVA_BINARY%...
406+
407-
    "%JAVA_LOCATION%\%JAVA_BINARY%" %JAVA_ARGUMENTS%
407+
408
echo %CUR_DATE% %TIME%   Removing "%ProgramFiles%\Java\jre*" directories...>> "%LOGPATH%\%LOGFILE%"
409
echo %CUR_DATE% %TIME%   Removing "%ProgramFiles%\Java\jre*" directories...
410
for /D /R "%ProgramFiles%\Java\" %%x in (j2re*) do if exist "%%x" rmdir /S /Q "%%x">> "%LOGPATH%\%LOGFILE%"
411
for /D /R "%ProgramFiles%\Java\" %%x in (jre*) do if exist "%%x" rmdir /S /Q "%%x">> "%LOGPATH%\%LOGFILE%"
412
if exist "%ProgramFiles%\JavaSoft\JRE" rmdir /S /Q "%ProgramFiles%\JavaSoft\JRE" >> "%LOGPATH%\%LOGFILE%"
413
414
:: Nuke Java installer cache ( thanks to cannibalkitteh )
415
echo %CUR_DATE% %TIME%   Purging Java installer cache...>> "%LOGPATH%\%LOGFILE%"
416
echo %CUR_DATE% %TIME%   Purging Java installer cache...
417
:: XP VERSION
418
if %OS_VERSION%==XP (
419
    :: Get list of users, put it in a file, then use it to iterate through each users profile, deleting the AU folder
420
    dir "%SystemDrive%\Documents and Settings\" /B > %TEMP%\userlist.txt
421
    for /f "tokens=* delims= " %%a in (%TEMP%\userlist.txt) do (
422
		if exist "%SystemDrive%\Documents and Settings\%%a\AppData\LocalLow\Sun\Java\AU" rmdir /S /Q "%SystemDrive%\Documents and Settings\%%a\AppData\LocalLow\Sun\Java\AU" 2>NUL
423
	)
424
    for /D /R "%SystemDrive%\Documents and Settings\" %%x in (jre*) do if exist "%%x" rmdir /S /Q "%%x" 2>NUL
425
) else (
426
	:: ALL OTHER VERSIONS OF WINDOWS
427
    :: Get list of users, put it in a file, then use it to iterate through each users profile, deleting the AU folder
428
    dir %SystemDrive%\Users /B > %TEMP%\userlist.txt
429
    for /f "tokens=* delims= " %%a in (%TEMP%\userlist.txt) do rmdir /S /Q "%SystemDrive%\Users\%%a\AppData\LocalLow\Sun\Java\AU" 2>NUL
430
    :: Get the other JRE directories
431
    for /D /R "%SystemDrive%\Users" %%x in (jre*) do rmdir /S /Q "%%x" 2>NUL
432
    )
433
434
:: Miscellaneous stuff, sometimes left over by the installers
435
echo %CUR_DATE% %TIME%   Searching for and purging other Java Runtime-related directories...>> "%LOGPATH%\%LOGFILE%"
436
echo %CUR_DATE% %TIME%   Searching for and purging other Java Runtime-related directories...
437
del /F /Q %SystemDrive%\1033.mst >> "%LOGPATH%\%LOGFILE%" 2>NUL
438
del /F /S /Q "%SystemDrive%\J2SE Runtime Environment*" >> "%LOGPATH%\%LOGFILE%" 2>NUL
439
echo.
440
441
echo %CUR_DATE% %TIME%   File and directory cleanup done.>> "%LOGPATH%\%LOGFILE%"
442
echo %CUR_DATE% %TIME%   File and directory cleanup done.
443
echo. >> "%LOGPATH%\%LOGFILE%"
444
echo.
445
446
:: Java Re-installation (x64): Check if we wanted to reinstall the JRE.
447
if %REINSTALL_JAVA_x64%==yes (
448
    echo %CUR_DATE% %TIME% ! Variable "REINSTALL_JAVA_x64" was set to 'yes'. Now installing %JAVA_BINARY_x64%...>> "%LOGPATH%\%LOGFILE%"
449
    echo %CUR_DATE% %TIME% ! Variable "REINSTALL_JAVA_x64" was set to 'yes'. Now installing %JAVA_BINARY_x64%...
450
    "%JAVA_LOCATION_x64%\%JAVA_BINARY_x64%" %JAVA_ARGUMENTS_x64%
451
    java -version
452
    echo Done.>> "%LOGPATH%\%LOGFILE%"
453
    )
454
455
:: Java Re-installation (x86): Check if we wanted to reinstall the JRE.
456
if %REINSTALL_JAVA_x86%==yes (
457
    echo %CUR_DATE% %TIME% ! Variable "REINSTALL_JAVA_x86" was set to 'yes'. Now installing %JAVA_BINARY_x86%...>> "%LOGPATH%\%LOGFILE%"
458
    echo %CUR_DATE% %TIME% ! Variable "REINSTALL_JAVA_x86" was set to 'yes'. Now installing %JAVA_BINARY_x86%...
459
    "%JAVA_LOCATION_x86%\%JAVA_BINARY_x86%" %JAVA_ARGUMENTS_x86%
460
    java -version
461
    echo Done.>> "%LOGPATH%\%LOGFILE%"
462
    )
463
464
:: Done.
465
echo %CUR_DATE% %TIME%   Registry hive backups: %TEMP%\java_purge_registry_backup\>> "%LOGPATH%\%LOGFILE%"
466
echo %CUR_DATE% %TIME%   Registry hive backups: %TEMP%\java_purge_registry_backup\
467
echo %CUR_DATE% %TIME%   Log file: "%LOGPATH%\%LOGFILE%">> "%LOGPATH%\%LOGFILE%"
468
echo %CUR_DATE% %TIME%   Log file: "%LOGPATH%\%LOGFILE%"
469
echo %CUR_DATE% %TIME%   JAVA NUKER COMPLETE. Recommend rebooting and washing your hands.>> "%LOGPATH%\%LOGFILE%"
470
echo %CUR_DATE% %TIME%   JAVA NUKER COMPLETE. Recommend rebooting and washing your hands.
471
472
:: Return exit code to SCCM/PDQ Deploy/PSexec/etc
473
exit /B %EXIT_CODE%