This discussion is archived
3 Replies Latest reply: Jun 20, 2012 6:01 AM by gimbal2 RSS

cmd script for silent installation of JRE 7 and uninstallation of older JRE

944771 Newbie
Currently Being Moderated
Hi!

I'd like to share a Windows command script for silent installation of JRE 7 and uninstallation of older versions. I wrote that script as I was not able to find anything appropriate for installing both 32-bit and 64-bit versions of JRE. The script can be run from a network share and as a startup script (which runs under system account on Windows).

For installation/uninstallation the script uses MSI files which are created when an offline installation file is run.
E.g. if you run jre-7u5-windows-x64.exe on a 64-bit Windows, the following folder is created:
"*%APPDATA%\Sun\Java\jre1.7.0_05_x64*" (APPDATA is an environment variable).

So, you must copy such folders for all versions of JRE that should be uninstalled or installed to the folder where the script is placed. The following listing shows the folders for the current script:
prompt>dir
...
19.06.2012  18:19             1.710 install_jre7.cmd
19.06.2012  13:07    <DIR>          jre1.6.0_32
19.06.2012  13:06    <DIR>          jre1.6.0_32_x64
19.06.2012  10:56    <DIR>          jre1.6.0_33
19.06.2012  10:57    <DIR>          jre1.6.0_33_x64
19.06.2012  18:06    <DIR>          jre1.7.0_04
19.06.2012  18:11    <DIR>          jre1.7.0_04_x64
19.06.2012  12:07    <DIR>          jre1.7.0_05
19.06.2012  12:05    <DIR>          jre1.7.0_05_x64
I tested the script in a Windows network where those versions of JRE were previously installed through offline EXE installers.

The script can be adapted for future versions of JRE 7 by updating the old_jre_ver and new_jre_ver variables and adding folders with MSI files for the new version.
------------------------------- install_jre7.cmd -------------------------------
rem - This script installs Java SE Runtime Environment (JRE) v. 7.*
rem - and uninstalls the specified older versions of JRE.
rem - Successfully tested on MS Windows XP Pro. SP3, Windows 7 Pro. SP1 x86/x64,
rem - Windows Server 2003 Std. SP2

rem - Download page: http://www.oracle.com/technetwork/java/javase/downloads/

rem - List of old versions of JRE that should be uninstalled
set old_jre_ver=1.6.0_32 1.6.0_33 1.7.0_04

rem - The new version of JRE
set new_jre_ver=1.7.0_05

eventcreate /l application /so "%~n0%~x0" /t information /id 1 /d "Starting %~f0"
taskkill /f /im firefox.exe /im iexplore.exe /im jqs.exe

rem - Directory path of this script.
set p=%~d0%~p0

rem - Uninstall old versions of JRE

if not defined ProgramFiles(x86) goto Uninst32
rem - Uninstall old 64-bit JRE
for %%v in (%old_jre_ver%) do (
  msiexec /x "%p%jre%%v_x64\jre%%v.msi" /qn /norestart
)

:Uninst32
rem - Uninstall old 32-bit JRE
for %%v in (%old_jre_ver%) do (
  msiexec /x "%p%jre%%v\jre%%v.msi" /qn /norestart
)


rem - Install new version of JRE if not installed already
java -version
if %errorlevel% GTR 0 goto Inst
java -version 2>&1 | findstr /l %new_jre_ver%
if %errorlevel%==0 goto TheEnd

:Inst
if not defined ProgramFiles(x86) goto Inst32
rem - Install 64-bit JRE silently
msiexec /i "%p%jre%new_jre_ver%_x64\jre%new_jre_ver%.msi" /qn /norestart

:Inst32
rem - Install 32-bit JRE silently
msiexec /i "%p%jre%new_jre_ver%\jre%new_jre_ver%.msi" /qn /norestart

rem - Remove Java Quick Starter Service
sc stop JavaQuickStarterService
sc delete JavaQuickStarterService

:TheEnd
eventcreate /l application /so "%~n0%~x0" /t information /id 1 /d "%~f0: Done"
------------------------------- install_jre7.cmd -------------------------------
Your suggestions for improving the script are welcome but, please, test everything thoroughly at least on Windows 7 x86 and x64.

-- rpr.
  • 1. Re: cmd script for silent installation of JRE 7 and uninstallation of older JRE
    gimbal2 Guru
    Currently Being Moderated
    Your effort is commendable, but this is really not the proper medium for sharing it as forum posts are really short lived - plus people are less likely to read this as the way you titled it, it looks like you're ASKING for a script in stead of offering one. Its quite unique that people come to share stuff ;)

    I would put the script somewhere far more permanent and visible and perhaps then post a link to it here to share it. Github or Google code are popular places to make these sorts of things available.
  • 2. Re: cmd script for silent installation of JRE 7 and uninstallation of older JRE
    944771 Newbie
    Currently Being Moderated
    I'd say the forum posts are not short lived. E.g. on groups.google.com I can still read my USENET posts written in 1996. On this forum I see posts 5 years old. So, search engines will find this script and possible comments and improvements.

    Moreover, I haven't marked my post as a question.

    -- rpr.
  • 3. Re: cmd script for silent installation of JRE 7 and uninstallation of older JRE
    gimbal2 Guru
    Currently Being Moderated
    Yeah the beauty of a forum is that stuff stays around forever - also one of the downsides as outdated or wrong information also sticks. Now if only people would actually take the time to search for stuff in stead of coming here, opening a thread and asking the same question that has been asked and answered a billion times prior...
    Moreover, I haven't marked my post as a question.
    That just means there are no points to be had for providing a winning answer, another reason not to bother with this thread ;)

    No really, even when it doesn't apply to me: nice work all the same. It would be a shame if it went to waste because you misunderstand the purpose of this forum.