通过静默安装将Java安装到具有空格的目录中 [英] Installing Java with silent install into a directory with spaces

查看:164
本文介绍了通过静默安装将Java安装到具有空格的目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我要使用的命令...

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

这将弹出Windows Installer对话框。 p>

当我使用...

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

p>

注意:程序文件(x86)只是一个例子。这是安装在客户端站点,他们选择安装目录,因此我们必须能够支持任何目录,他们可能指定。



任何想法如何我可以做一个沉默安装但仍使用长路径名称?


$ b

UPDATE: $ b

我以为我会分享最终的解决方案。一个很酷的事情,我发现,我想共享是,你可以禁止自动重新启动安装,它返回一个退出代码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)
{
//这只是查看错误代码列表并返回相应的消息
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


I am trying to install Java using the silent mode and also specify an installation directory that contains spaces. When I do this it pops up the "Windows Installer" dialog box indicating one of the parameters is incorrect. If I use the short path name it works correctly, but I really would prefer not to use the short directory name because that is the value that gets stored in the Registry.

The command I want to use...

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

This pops up the Windows Installer dialog box.

When I use...

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

This works.

NOTE: "Program Files (x86)" is just an example. This is installed at client sites and they choose the install directory, therefore we have to be able to support any directory they may specify.

Any idea how I can do a silent install but still use the long path name?

UPDATE:

I thought I would share the final solution. One cool thing I found that I wanted to share is that you can suppress the auto-reboot of install and it returns an exit code of 3010. Therefore you can defer the reboot to another time. Here is the code (rewritten a bit to eliminate a bunch of our own abstraction)

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;
}

解决方案

i recall encountering this issue before....

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

reference :

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安装到具有空格的目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆