├── README.md └── javaUpdate.cmd /README.md: -------------------------------------------------------------------------------- 1 | # Auto-Java-Updater 2 | Keep Java up to date in Windows! Remove redundant installations! 3 | 4 | 5 | Java has one MAJOR flaw in windows, you can't keep it up to date automatically. The "Auto Update" feature just downloads new updates, and doesn't install them unless you click. Also when it does install a new version, it doesn't remove the old version. That wastes space and is no good. The software helps. Schedule it to run every day and it will keep your JRE running happy! -------------------------------------------------------------------------------- /javaUpdate.cmd: -------------------------------------------------------------------------------- 1 | @::-----UAC Prompt---------------------------------- 2 | @echo off 3 | NET SESSION >nul 2>&1 && goto noUAC 4 | title. 5 | set n=%0 %* 6 | set n=%n:"=" ^& Chr(34) ^& "% 7 | echo Set objShell = CreateObject("Shell.Application")>"%tmp%\cmdUAC.vbs" 8 | echo objShell.ShellExecute "cmd.exe", "/c start " ^& Chr(34) ^& "." ^& Chr(34) ^& " /d " ^& Chr(34) ^& "%CD%" ^& Chr(34) ^& " cmd /c %n%", "", "runas", ^1>>"%tmp%\cmdUAC.vbs" 9 | echo Not Admin, Attempting to elevate... 10 | cscript "%tmp%\cmdUAC.vbs" //Nologo 11 | del "%tmp%\cmdUAC.vbs" 12 | exit /b 13 | :noUAC 14 | 15 | setlocal enableextensions enabledelayedexpansion 16 | color 17 17 | title Java removal/update tool v0.9 18 | 19 | echo. 20 | echo This software is brought to you by Grintor. 21 | echo ^ 22 | echo. 23 | echo This program is free software. 24 | echo This program IS PROVIDED WITHOUT WARRANTY, EITHER EXPRESSED OR IMPLIED. 25 | echo This program is copyrighted under the terms of GPLv3: 26 | echo see ^. 27 | echo. 28 | FOR /L %%n IN (1,1,10) DO ping -n 2 127.0.0.1 > nul & nul & nul 2>&1 || echo Installing cURL... && start /wait msiexec /i https://s3.amazonaws.com/grintor-public/curl.msi /q 38 | 39 | cls 40 | echo. 41 | echo Searching for latest version of Java... 42 | ping -n 1 google.com > nul || goto error 43 | 44 | 45 | ::----------- Find the latest java version---------------------------------- 46 | FOR /F "tokens=2 delims=< > " %%n IN ('curl.exe -s -L http://javadl-esd.sun.com/update/1.8.0/map-m-1.8.0.xml ^| find /i "https:"') DO set URL1=%%n 47 | FOR /F "tokens=2 delims=< > " %%n IN ('curl.exe -s -L -k %URL1% ^| find /i ""') DO set RemoteJavaVersionFull=%%n 48 | set RemoteJavaVersion=%RemoteJavaVersionFull:~0,8% 49 | echo The latest version of java is %RemoteJavaVersion%. 50 | 51 | 52 | 53 | 54 | ::----------- Find the local Java version----------------------------------- 55 | set LocalJavaVersion=None 56 | FOR /F "tokens=1-15" %%n IN ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s ^& reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /s 2^> nul') DO ( 57 | 58 | if '%%n'=='InstallSource' ( 59 | set p=%%p%%q%%r%%s%%t%%u%%v%%w%%x%%y%%z 60 | set p=!p: =\! 61 | set p=!p:\= ! 62 | for %%n in (!p!) do set c=%%n 63 | ) 64 | 65 | if '%%n'=='DisplayName' ( 66 | set p=%%p 67 | if "!p:~0,4!"=="Java" if not "%%q"=="Auto" if not '!LocalJavaVersion!'=='None' (set LocalJavaVersion=Multi) ELSE (set LocalJavaVersion=!c:~3!) 68 | if "!p:~0,4!"=="J2SE" if not '!LocalJavaVersion!'=='None' (set LocalJavaVersion=Multi) ELSE (set LocalJavaVersion=!c:~3!) 69 | ) 70 | ) 71 | 72 | if '%LocalJavaVersion%'=='None' echo There is no local version of Java. & goto install 73 | if '%LocalJavaVersion%'=='Multi' echo There are multiple local versions of Java installed. & goto uninstall 74 | echo The local version of Java is %LocalJavaVersion%. 75 | 76 | 77 | 78 | ::----------- If they match, skip to the end--------------------------------- 79 | if '%RemoteJavaVersion%'=='%LocalJavaVersion%' (goto finished) ELSE (echo The Local version of Java is out of date.) 80 | 81 | 82 | 83 | 84 | ::----------- Uninstall all currently installed java versions---------------- 85 | :uninstall 86 | if '%LocalJavaVersion%'=='Multi' (echo Uninstalling all local versions of Java...) ELSE (echo Uninstalling the local version of Java...) 87 | FOR /F "tokens=1-4" %%n IN ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s ^& reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /s 2^> nul') DO ( 88 | 89 | if '%%n'=='UninstallString' ( 90 | set c=%%q 91 | set c=!c:/I=/X! 92 | ) 93 | 94 | if '%%n'=='DisplayName' ( 95 | set d=%%p 96 | if "!d:~0,4!"=="Java" if not "%%q"=="Auto" msiexec.exe !c! /qn & ping -n 11 127.0.0.1 > nul 97 | if "!d:~0,4!"=="J2SE" msiexec.exe !c! /qn & ping -n 11 127.0.0.1 > nul 98 | ) 99 | ) 100 | 101 | 102 | 103 | ::----------- Download the latest java, install, delete the installer.------- 104 | :install 105 | echo Downloading latest version of Java... 106 | set url2=http://javadl.sun.com/webapps/download/GetFile/%RemoteJavaVersionFull%/windows-i586/xpiinstall.exe 107 | curl.exe -s -L -k -o %tmp%\java_inst.exe %url2% 108 | echo Installing latest version of Java... 109 | start /wait %tmp%\java_inst.exe /s 110 | ping 127.0.0.1 > nul 111 | del %tmp%\java_inst.exe 112 | 113 | 114 | 115 | ::----------- Up to date ---------------------------------------------------- 116 | :finished 117 | echo Your Java is up to date. 118 | echo. 119 | 120 | 121 | ::----------- There was an error--------------------------------------------- 122 | goto noerror 123 | :error 124 | echo There was a network error. Please try again. 125 | :noerror 126 | 127 | endlocal 128 | FOR /L %%n IN (1,1,10) DO ping -n 2 127.0.0.1 > nul &