Installing Java with silent install into a directory with spaces

10,470

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

Share:
10,470
Gene S
Author by

Gene S

Currently C# Developer. Experience with Windows Services / WPF / Winforms / ASP .NET / Silverlight 15 years FoxPro Developer Avid reader; westerns and fantasy are favorites.

Updated on June 16, 2022

Comments

  • Gene S
    Gene S almost 2 years

    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;
    }
    
  • Ingo
    Ingo about 11 years
    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)".
  • Admin
    Admin about 11 years
    @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.
  • Adrian Pronk
    Adrian Pronk about 11 years
    I agree with @pst: The main problem is cmd.exe's command-line handling which is fundamentally brain-dead.
  • Ingo
    Ingo about 11 years
    @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.