gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 13:26:16 33 4
gpt4 key购买 nike

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

我要使用的命令...

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

这会弹出 Windows Installer 对话框。

当我使用...

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

这有效。

注意:“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;
}

最佳答案

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

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\""

引用:

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

关于java - 使用静默安装将 Java 安装到带空格的目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14837697/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com