2013-02-12 65 views
6

我試圖使用靜默方式安裝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; 
} 
+1

您是否嘗試過的%ProgramFiles%? – vqdave 2013-02-12 18:59:26

+0

我很抱歉不清楚。 「Program Files(x86)」只是一個例子。我已經改變了這個問題來正確地反映這一點。 – 2013-02-12 20:58:09

回答

5

我記得以前遇到這個問題....

你需要傳遞路徑的時候使用引號安裝程序如果 路徑有空格。由於路徑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

+2

我每隔一週就問自己,MS的一個****文件有一個愚蠢的想法,即命名一個經常使用的目錄「Program Files(x86)」。 – Ingo 2013-02-12 21:58:25

+1

不要採取這種錯誤的方式,但是,我想吻*你:) – 2013-02-12 22:27:05

+1

@Ingo與「真棒」shell語法和cmd.exe的統一報價/參數處理相比,這實際上不是一個問題,事實上,整個子系統用來調用一個程序..除外,不是。 – 2013-02-12 22:35:45