Remove Java and install Latest Version

At the company where I work we don’t have full domain rights. There is no SCCM Server. There is an other software deploy program that we only have rights to send it to computers, not to create packages. So I create my own scripts to update computers.

This script I use to update Java on all computers. Windows 7 and Windows 10.

@echo off
REM #########################################
REM ##### Created by Daag van der Meer  #####
REM ##### http://blog.van-daag.nl       #####
REM ##### Filename InstallJava.cmd      #####
REM #########################################
PING 1.1.1.1 -n 1 -w 900 >NUL

SET JavaFile=<JAVAFilename.msi>
SET JavaLoc=\\<Java MSI Location\Java\Update
SET LOGLOC=%Systemdrive%\logs

REM ############### Create Log Dir ###################
mkdir %LOGLOC%
attrib +s +h %Systemdrive%\logs
Goto INSTALL

:INSTALL
REM ######## Check Java Installed #############
set Logfile=%LOGLOC%\%JavaFile%.log
if not exist "%Logfile%" (
echo Java is Installed on %date% at %time% >> %LogFile%
GOTO JAVASTART)

GOTO END

:JAVASTART
REM ###### Uninstall All Java versions ####
Echo Removing All Java Versions
wmic product where "name like 'Java%%'" call uninstall /nointeractive

REM Java Silent Install version 8111 (replace with your java version downloaded)
Echo Installing Java
copy %JavaLoc%\%JavaFile% %LOGLOC%
start /wait msiexec.exe /i %LOGLOC%\%JavaFile% JU=0 JAVAUPDATE=0 AUTOUPDATECHECK=0 RebootYesNo=No
del %LOGLOC%\%JavaFile%

REM Disable Auto Update
echo Disable Auto Updates
reg delete "HKLM\SOFTWARE\JavaSoft\Java Update\Policy\jucheck" /v "UpdateSchedule" /f
reg delete "HKLM\SOFTWARE\JavaSoft\Java Update\Policy\jucheck" /v "UpdateMin" /f
reg add "HKLM\SOFTWARE\JavaSoft\Java Update\Policy" /v EnableJavaUpdate /t REG_DWORD /d 00000000 /f
reg add "HKLM\SOFTWARE\JavaSoft\Java Update\Policy" /v EnableAutoUpdateCheck /t REG_DWORD /d 00000000 /f
reg add "HKCU\SOFTWARE\JavaSoft\Java Update\Policy" /v EnableJavaUpdate /t REG_DWORD /d 00000000 /f

reg delete "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Update\Policy\jucheck" /v "UpdateSchedule" /f
reg delete "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Update\Policy\jucheck" /v "UpdateMin" /f
reg add "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Update\Policy" /v EnableJavaUpdate /t REG_DWORD /d 00000000 /f
reg add "HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Update\Policy" /v EnableAutoUpdateCheck /t REG_DWORD /d 00000000 /f

Goto END
:NO
del %LOGLOC%\%JavaFile%.log

:END

Add this script to the machine policy.

 

When a computer has the login screen this batch file runs and removes / installs Java.