【问题标题】:run a .msi file in java在 java 中运行 .msi 文件
【发布时间】:2023-04-01 05:54:01
【问题描述】:

所以我尝试像运行 exe 文件一样运行 .msi 文件,这可能是问题所在。我收到此错误消息

java.io.IOException:无法运行程序“\”:CreateProcess 错误=193, %1 不是有效的 Win32 应用程序

       try {   Runtime rf = Runtime.getRuntime(); 
                   Process pf = rf.exec("\\IE8fix.msi");    
                } catch(Exception e) {                 
                    System.out.println(e.toString());                 
                            e.printStackTrace();
                                                    } 

【问题讨论】:

  • 我怀疑 java 可以在 windows 网络上执行任何操作(在 \\h 下尝试使用本地版本的 MSI
  • 您似乎正在尝试启动 IE 8 修复程序。为什么不能双击运行呢?

标签: java windows-installer


【解决方案1】:

Windows 安装程序位于 %windir%\msiexec.exe MSI 文件不是独立的。它需要像msiexec \"file.msi\"一样运行 所以使用:

try {
   Runtime rf = Runtime.getRuntime(); 
   Process pf = rf.exec("msiexec /i \"\\IE8fix.msi\"");    
} catch(Exception e) {                 
   //System.out.println(e.toString()); // not necessary       
   e.printStackTrace();
} 

【讨论】:

  • 如何为 /a 等安装添加斜线?
  • 没关系,我想通了,它就在 msiexec 之后和 \ 之前,谢谢!
  • 对我来说它只适用于Process prc = Runtime.getRuntime().exec(String.format("msiexec /i %s", installationFile)); 然后,像prc.getErrorStream() 这样的流可用并且很有用
【解决方案2】:

.msi 文件不是像 exe 那样的独立程序,它应该像这样从 Windows 安装程序运行(我希望这是正确的):

Process pf = rf.exec("msiexec \"\\IE8fix.msi\"");    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多