我試圖使用靜默方式安裝Java,並指定包含空格的安裝目錄。當我這樣做時,它會彈出「Windows安裝程序」對話框,指出其中一個參數不正確。如果我使用短路徑名稱,它可以正常工作,但我真的不希望使用短目錄名稱,因爲這是存儲在註冊表中的值。將靜默安裝Java安裝到包含空格的目錄中
我想用命令
jre-6u39-windows-i586.exe /s INSTALLDIR="C:\Program Files (x86)\Java"
這個彈出的Windows安裝程序對話框。
當我使用...
jre-6u39-windows-i586.exe /s INSTALLDIR=C:\Progra~2\Java
這工作。
注意:「Program Files(x86)」只是一個示例。這是安裝在客戶端,他們選擇安裝目錄,因此我們必須能夠支持他們可能指定的任何目錄。
任何想法如何我可以做一個沉默的安裝,但仍然使用長路徑名?
UPDATE:
,我想我會分享最終的解決方案。我發現我想分享的一件很酷的事情是,您可以禁止自動重新啓動安裝,並返回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%? – vqdave 2013-02-12 18:59:26
我很抱歉不清楚。 「Program Files(x86)」只是一個例子。我已經改變了這個問題來正確地反映這一點。 – 2013-02-12 20:58:09