将Java静默安装到具有空格的目录中

我正在尝试使用静默模式安装Java,并指定一个包含空格的安装目录。 当我这样做时,popup“Windows安装程序”对话框,指出其中一个参数是不正确的。 如果我使用短path名称,它的工作是正确的,但我真的不希望使用短目录名称,因为这是存储在registry中的值。

我想要使​​用的命令…

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

这会popupWindows Installer对话框。

当我使用…

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

这工作。

注意:“Program Files(x86)”只是一个例子。 这是安装在客户端,他们select安装目录,因此我们必须能够支持他们可能指定的任何目录。

任何想法如何我可以做一个沉默的安装,但仍然使用长path名?

更新:

我想我会分享最后的解决scheme。 一个很酷的事情,我发现我想分享的是,你可以禁止安装的自动重启,它返回一个退出代码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; } 

我记得以前遇到这个问题….

如果路径中有空格,则需要在将路径传递给安装程序时使用引号。 由于路径arg已经在引号中,所以您需要用“\”来转义每个引号,以便通过。 所以命令将是

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

参考:

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