How to Install java run-time /jre on a custom path using a Batch script

automated-installbatch-fileinstallationwindows 7windows-installer

Im trying to create a bat file to make an unattended installation with sccm.
I downloaded jre-7u55-windows-i586.exe from http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html (jre-7u55-windows-i586 is used for legacy application we are running)

and followed https://www.java.com/en/download/help/silent_install.xml
and could come in to

"%~dp0jre-7u55-windows-i586.exe" /s /v"AgreeToLicense=YES INSTALLDIR=C:\Program Files\test\test1\Java\jre1.7.0.55 IEXPLORER=1 MOZILLA=1 REBOOT=SUPRESS JAVAUPDATE=0 SYSTRAY=0"

Above script will work only if the installation directory is other than C:\Program Files\

For example it will work if

INSTALLDIR=**C:\test\**test1\Java\jre1.7.0.55

..

But I want INSTALLDIR to be

C:\Program Files\test\test1\Java\jre1.7.0.55

I tried adding following

INSTALLDIR="C:\Program Files\test\test1\Java\jre1.7.0.55" — not working

INSTALLDIR='C:\Program Files\test\test1\Java\jre1.7.0.55' — not working

/INSTALLDIR=C:\Program Files\test\test1\Java\jre1.7.0.55 — not working

"INSTALLDIR=C:\Program Files\test\test1\Java\jre1.7.0.55" — not working

All the time im getting this .. (Sounds rather misleading message)

enter image description here

I cant understand why i cant install it on C:\Program Files\test\test1\Java\jre1.7.0.55.. What Im missing here? What is wrong with C:\Program Files\test\test1\Java\jre1.7.0.55 . Pls help

(I do have admin rights for my account)

Best Answer

You can derive the short names from the full path to overcome the limits mentioned in your question.

REM Insert full path to executable here as a literal string or environment
Call :s_Install_Short "C:\Program Files\test\test1\Java\jre1.7.0.55"
Goto :EOF

:s_Install_Short
REM Block attempts to pass no parameter
If "%~1" EQU "" Goto :EOF

REM %~s1 contains the path in the first parameter as a shortened string
"%~dp0jre-7u55-windows-i586.exe" /s /v"AgreeToLicense=YES INSTALLDIR=%~s1 IEXPLORER=1 MOZILLA=1 REBOOT=SUPRESS JAVAUPDATE=0 SYSTRAY=0"

Goto :EOF

The use of %~s1 would turn C:\Program Files\test\test1\Java\jre1.7.0.55 into something similar to C:\PROGRA~1\test\test1\Java\jre1.7.0.55