【发布时间】:2013-01-28 01:31:03
【问题描述】:
我正在尝试使用静默模式安装 Java,并指定包含空格的安装目录。当我这样做时,它会弹出“Windows Installer”对话框,指示其中一个参数不正确。如果我使用短路径名,它可以正常工作,但我真的不希望使用短目录名,因为这是存储在注册表中的值。
我要使用的命令...
jre-6u39-windows-i586.exe /s INSTALLDIR="C:\Program Files (x86)\Java"
这会弹出 Windows 安装程序对话框。
当我使用...
jre-6u39-windows-i586.exe /s INSTALLDIR=C:\Progra~2\Java
这行得通。
注意:“程序文件 (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;
}
【问题讨论】:
-
你试过 %ProgramFiles% 吗?
-
我很抱歉不清楚。 “Program Files (x86)”只是一个例子。我已更改问题以正确反映这一点。
标签: java windows command-line cmd installation