6

I am trying to install Java using the silent mode and also specify an installation directory that contains spaces. When I do this it pops up the "Windows Installer" dialog box indicating one of the parameters is incorrect. If I use the short path name it works correctly, but I really would prefer not to use the short directory name because that is the value that gets stored in the Registry.

The command I want to use...

jre-6u39-windows-i586.exe /s INSTALLDIR="C:\Program Files (x86)\Java"

This pops up the Windows Installer dialog box.

When I use...

jre-6u39-windows-i586.exe /s INSTALLDIR=C:\Progra~2\Java

This works.

NOTE: "Program Files (x86)" is just an example. This is installed at client sites and they choose the install directory, therefore we have to be able to support any directory they may specify.

Any idea how I can do a silent install but still use the long path name?

UPDATE:

I thought I would share the final solution. One cool thing I found that I wanted to share is that you can suppress the auto-reboot of install and it returns an exit code of 3010. Therefore you can defer the reboot to another time. Here is the code (rewritten a bit to eliminate a bunch of our own abstraction)

public bool InstallJava(string installPath, string logFile)
{
    bool rebootRequired = false;

    string fullLogFileName = Path.Combine(logFile, "JavaInstall.log");
    string arguments = string.Format("/s /v\"/qn REBOOT=Suppress INSTALLDIR=\\\"{0}\\\" STATIC=1 /L \\\"{1}\\\"\"", installPath, fullLogFileName);

    ProcessStartInfo startInfo = new ProcessStartInfo { RedirectStandardError = true, RedirectStandardOutput = true, RedirectStandardInput = true, UseShellExecute = false, CreateNoWindow = true, 
    FileName = "jre-7u25-windows-x64.exe",  Arguments = arguments };

    var process = Process.Start(startInfo);
    process.WaitForExit();

    if (process.ExitCode == 3010)
        rebootRequired = true;

    else if (process.ExitCode != 0)
    {
        // This just looks through the list of error codes and returns the appropriate message
        string expandedMessage = ExpandExitCode(StringResources.JAVA_INSTALL_ERROR, process.ExitCode, fullLogFileName);
        throw new Exception(expandedMessage);
    }

    return rebootRequired;
}
2
  • 1
    Have you tried %ProgramFiles%?
    – vqdave
    Feb 12, 2013 at 18:59
  • I apologize for not being clear. "Program Files (x86)" is just an example. I have changed the question to properly reflect this.
    – Gene S
    Feb 12, 2013 at 20:58

1 Answer 1

5

i recall encountering this issue before....

You need to use quotes when passing paths to the installer if the paths have spaces. Because the path arg is already in quotes, you need to escape each quote with a '\' so it gets passed through. So the command would be

       j2re.exe /s /v"/qn INSTALLDIR=\"C:\Program Files\JRE\""

reference :

http://docs.oracle.com/javase/1.5.0/docs/guide/deployment/deployment-guide/silent.html

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4966488

4
  • 2
    I ask myself every other week what an a****le at MS had the silly idea to name an often used directory "Program Files (x86)".
    – Ingo
    Feb 12, 2013 at 21:58
  • 1
    @Ingo That's hardly an issue compared with the "awesome" shell syntax and uniform quote/argument handling of cmd.exe and, in fact, the entire subsystem used to invoke a program .. except, not.
    – user166390
    Feb 12, 2013 at 22:35
  • I agree with @pst: The main problem is cmd.exe's command-line handling which is fundamentally brain-dead. Feb 13, 2013 at 8:14
  • 1
    @pst Correct. MS shows for decades that they don't give a sh*t about people who try to use their OSs from the command line.
    – Ingo
    Feb 13, 2013 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.