使用静默安装将Java安装到带空格的目录中

Gen*_*e S 6 java windows command-line install cmd

我正在尝试使用静默模式安装Java,并指定包含空格的安装目录.当我这样做时,它弹出"Windows Installer"对话框,指示其中一个参数不正确.如果我使用短路径名称它可以正常工作,但我真的不想使用短目录名称,因为这是存储在注册表中的值.

我想要使​​用的命令......

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

这会弹出Windows Installer对话框.

当我用...

jre-6u39-windows-i586.exe /s INSTALLDIR=C:\Progra~2\Java
Run Code Online (Sandbox Code Playgroud)

这有效.

注意:"Program Files(x86)"只是一个例子.它安装在客户端站点并且他们选择安装目录,因此我们必须能够支持他们可能指定的任何目录.

知道如何进行静默安装,但仍然使用长路径名称?

更新:

我想我会分享最终解决方案.我发现我想分享的一个很酷的事情是你可以禁止自动重启安装,它会返回3010的退出代码.因此你可以将重新启动推迟到另一个时间.这是代码(重写了一点,以消除一堆我们自己的抽象)

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;
}
Run Code Online (Sandbox Code Playgroud)

Nim*_*007 5

我记得之前遇到过这个问题....

如果路径有空格,则在将路径传递给安装程序时需要使用引号.因为路径arg已经在引号中,所以你需要使用'\'来转义每个引号,以便它被传递.所以命令就是

       j2re.exe /s /v"/qn INSTALLDIR=\"C:\Program Files\JRE\""
Run Code Online (Sandbox Code Playgroud)

参考:

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

  • 我每隔一周问自己,MS的一个****有什么愚蠢的想法来命名一个经常使用的目录"Program Files(x86)". (2认同)